How to read a tiff image (3D) that includes 2D images ? (imread gives only the first image)

14 次查看(过去 30 天)
I used the following codes to reconstruct a 3D image that includes 2D slices
for slice = 1 : numberOfSlices filename = sprintf('image #%d', slice);
fullFileName = fullfile(folder, filename);
if exist(fullFileName, 'file)
thisSlice = imread(fullFileName);
array3d(:,:,slice) = thisSlice;
end
end
Then, I use imwrite and to obtain a tiff file that includes all 2D slices.
Now, I want to find connected components in the 3D tiff file. But, if I use
imread() function gives only the first slice in the tiff image.
Can you help me to solve this problem ?

回答(2 个)

Walter Roberson
Walter Roberson 2016-1-9
Please show your code that does the writing with imwrite(), because when I try it it tells me clearly that you cannot use imwrite() with that many components and that the Tiff class needs to be used instead.
imread() documents an Index parameter for TIFF files to read a particular indexed file.
More control for TIFF files can be obtained using the TIFF class. However, there is no one call to return all of the images at once: you need to loop and read the "next" image each time. See http://www.mathworks.com/help/matlab/import_export/importing-images.html#br_c8to-1
  2 个评论
S C.Carl
S C.Carl 2016-1-9
Hi Walter, Thanks for your response. My imwrite code is this,
if (slice == startSliceNo)
imwrite(squeeze(myimg3d(:,:,slice)),[fileNameStrToSave,'.tif'],'tif', 'WriteMode', 'overwrite','Compression', 'none');
else
imwrite(squeeze(myimg3d(:,:,slice)),[fileNameStrToSave,'.tif'],'tif', 'WriteMode', 'append','Compression', 'none');
end
Now, my goal is to find the largest component in the "myimg3d.tif" So, if I use to read the image by imread as,
img = imread('myimg3d.tif')
Then, I am getting only the first slice in the "img". :( Please, someone can help me
Walter Roberson
Walter Roberson 2016-1-10
Look at the Index parameter that is documented in imread() for reading TIFF files. You need to loop reading by index until you get them all.

请先登录,再进行评论。


Image Analyst
Image Analyst 2016-1-10
Why are you saving that 3D file that you built up from the 2D slices? You've got the 3D array, so just start using it. Why try to save it out incorrectly and then read it back in and be surprised when it doesn't read in correctly? Like Walter said, you'd have to use the TIFF class, but I don't think you even need to save it. Or if you do, why not save it in a mat file?

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by