Opening and reading a given frame from a .tiff stack to then show on the screen

56 views (last 30 days)
Hello community. I have what I thought would be simple enough but having trouble opening a .tiff stack in matlab to do the following:
  1. For a 512x512 100 frame tiff file, first read a given frame (e.g. #5)
  2. display that image on the screen.
  3. 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

Accepted Answer

DGM
DGM on 9 May 2021
Edited: DGM on 9 May 2021
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.

More Answers (1)

hxen
hxen on 8 May 2021
So a follow up... I found that using uint16 to convert the data type helped. At first it makes a black screen... but it is clear the data is embedded. The for the 16 bit capture is very low. I had to use the colormap edit to adjust the minimum value displayed. I do not know what Fiji does to show the signal so nicely.
  1 Comment
DGM
DGM on 9 May 2021
If you want to normalize an image to the extent of its data, you can do:
mn=min(inpict(:));
mx=max(inpict(:));
outpict=(inpict - mn) ./ (mx-mn);
If you have IPT, you can do the same with imadjust/stretchlim
outpict = imadjust(inpict,stretchlim(inpict,[0 1]));

Sign in to comment.

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!