Opening and reading a given frame from a .tiff stack to then show on the screen
55 次查看(过去 30 天)
显示 更早的评论
Hello community. I have what I thought would be simple enough but having trouble opening a .tiff stack in matlab to do the following:
- For a 512x512 100 frame tiff file, first read a given frame (e.g. #5)
- display that image on the screen.
- Ultimately select a desired roi to then find the average pixel intensity.
For 1–2 above, with the following code I merely get a white screen. Yet (for those familary) with FiJi, I can see the actual image. I have not had need for image analysis for some time but recall this was very straight forward. Using the code attached, imshow(Z(:,:,5)) just shows a white screen, yet the matrix data is clearly there. Not sure what I might be doing wrong. Thanks in advance for the help.
fname = '01.tif';
info = imfinfo(fname);
num_images = numel(info)
imgs = zeros(512,512, num_images);
for jj = 1:num_images
imgs(:,:,jj) = double(imread(fname, jj, 'Info', info));
end
0 个评论
采纳的回答
DGM
2021-5-9
编辑:DGM
2021-5-9
This is why your images come out white.
imgs(:,:,jj) = double(imread(fname, jj, 'Info', info));
The image data in a file is usually an integer class. For example, if the image is uint8 and spans the entire range [0 255], then when you import it and cast it as double, it still spans the same range. It's just not integer anymore. The problem is that everything that handles images expects floating point images to be normalized [0 1]. Because of that, all the data is out of range. If you have IPT, you can just do im2double() instead of double(). That will cast the data and rescale it appropriately for the output class. If you don't have IPT, you can do
double(imread(fname, jj, 'Info', info))/255 % for uint8 images
% or
double(imread(fname, jj, 'Info', info))/65535 % for uint16 images
The fact that you have to rescale the image data significantly after using uint16 suggests that the image is either uint8 or simply isn't scaled to fit the range available (a lot of medical/technical images aren't).
If you want to know whether the images are uint8 or uint16 or something else because you're doing manual conversions like above without IPT, you can read the image into a temporary array, check class(mytempimg), and then cast/rescale it accordingly.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!