Filter löschen
Filter löschen

Save a 3D image to TIFF

65 Ansichten (letzte 30 Tage)
Ace
Ace am 14 Mai 2024
Beantwortet: Ace am 15 Mai 2024
Hi everyone,
I made a bwdist transform of some image and I am struggling to export it to the .tiff format. Actually I want to create a 2D image stack representing a 3D volume. I read about imwrite which says it cannot save an image with so many layers, and then about tiff function, but not sure how to you use it.. The original image was created using ImageJ and was in the tiff format, now I need to export the MATLAB's outcome back to tiff.
I'd appreciate your help.

Akzeptierte Antwort

Ace
Ace am 15 Mai 2024
In case somebody has a similar problem, it can be solved in the following way:
% Define the output filename for the multi-page TIFF stack
outputFilename = 'yourname.tif'; % Specify your desired output filename
% Create a Tiff object for writing the stack
t = Tiff(outputFilename, 'w');
% Get the size of the Mask - type your array's name
[numRows, numCols, numSlices] = size(Mask2);
% Loop through each slice and add it to the multi-page TIFF stack
for slice = 1:numSlices
% Extract the 2D slice
sliceData = Mask2(:, :, slice);
% Write the current slice to the multi-page TIFF stack
t.setTag('Photometric', Tiff.Photometric.MinIsBlack);
t.setTag('Compression', Tiff.Compression.None);
t.setTag('BitsPerSample', 32); % Set BitsPerSample to 32 for single precision data
t.setTag('SamplesPerPixel', 1);
t.setTag('SampleFormat', Tiff.SampleFormat.IEEEFP);
t.setTag('ImageLength', numRows);
t.setTag('ImageWidth', numCols);
t.setTag('PlanarConfiguration', Tiff.PlanarConfiguration.Chunky);
t.write(sliceData);
% Add a new page to the multi-page TIFF stack
if slice ~= numSlices
t.writeDirectory();
end
end
% Close the TIFF file
t.close();
You may also need to modify the min or max values when uploading your tif to other software such as ImageJ / Fiji to properly see all objects.

Weitere Antworten (1)

Matt J
Matt J am 14 Mai 2024
  1 Kommentar
Ace
Ace am 15 Mai 2024
Thanks but for some reason doesn't work for me - maybe something is wrongly adjusted to my case.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by