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

조회 수: 13 (최근 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 Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by