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

9 visualizzazioni (ultimi 30 giorni)
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();

Risposte (1)

Mann Baidi
Mann Baidi il 23 Lug 2024
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:

Community Treasure Hunt

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

Start Hunting!

Translated by