필터 지우기
필터 지우기

Save (multidimensional) Matlab matrix as float tiff and import to ImageJ

조회 수: 5 (최근 30일)
JustA Phys1k3r
JustA Phys1k3r 2016년 11월 7일
답변: Mann Baidi 대략 9시간 전
Hello, I usually work with ImageJ. For a project I need to export some data (e.g. 2 and 3 dimensional images) from Matlab and import it into ImageJ. I would like to use 32-bit float tiff as file format, which is usually working well with ImageJ.
I have used a similar code to the one below, but I am not able to import the generated .tiff file into ImageJ. The error is: ImageJ can only open 8 and 16 bit/channel images.
But this is not true, since I have imported 32-bit images in the .TIFF format in ImageJ before.
Please help me. I've been trying to find a workaround for a couple of hours now, but it was not successful at all.
Best, Florian
info = imfinfo(filename);
t = Tiff(filename, 'w');
tagstruct.ImageLength = size(timg, 1);
tagstruct.ImageWidth = size(timg, 2);
tagstruct.Compression = Tiff.Compression.None;
tagstruct.SampleFormat = Tiff.SampleFormat.IEEEFP;
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.BitsPerSample = info.BitsPerSample; % 32;
tagstruct.SamplesPerPixel = info.SamplesPerPixel; % 1;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
t.setTag(tagstruct);
t.write(timg);
t.close();

답변 (1개)

Mann Baidi
Mann Baidi 대략 9시간 전
Hi,
If you would like to create a double 32-bit float TIFF image in MATLAB using the LibTIFF library in MATLAB. You will have to convert the image data from 'double' datatype to 'single' datatype.
You can use the single function for converting the data as folllows:
% Generate random data for the 5 channels
R = single(rand(256, 256));
G = single(rand(256, 256));
B = single(rand(256, 256));
% Combine the channels into a 5-channel image
data = cat(3, R, G, B);
t = Tiff('output.tif', 'w');
t.setTag('ImageLength', size(data, 1));
t.setTag('ImageWidth', size(data, 2));
t.setTag('Photometric', Tiff.Photometric.MinIsBlack);
t.setTag('BitsPerSample', 32);
t.setTag('SampleFormat', Tiff.SampleFormat.IEEEFP);
t.setTag('SamplesPerPixel', 3);
t.setTag('Compression', Tiff.Compression.None);
t.setTag('PlanarConfiguration', Tiff.PlanarConfiguration.Chunky);
t.write(data);
% Close the file
t.close();
You can explore the single function using the documentation link mentioned below:

카테고리

Help CenterFile Exchange에서 Image Data에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by