Problem with .tif images display in matlab

30 次查看(过去 30 天)
I don't understand why my images (.TIF extension) are not showing clearly in MATLAB. When I try to view same picture in any other photo viewer app, I can see a clear image.Below I am attaching my image in matlab (on the left) and genral image in photo viewer(on the right). somebody please explain me what to do. Thanks in advance
I used the following simple code to display image in matlab.
img = imread("Water_T_90_t_inj_10_P_05_M10250.tif");
imshow(img)
  3 个评论
Rohit Thokala
Rohit Thokala 2021-12-18
Hi #Benjamin, I am attaching my image here. I can't upload .tif files directly so I am sending a Zipped version
Rohit Thokala
Rohit Thokala 2021-12-18
编辑:Rohit Thokala 2021-12-18
Thank you for the explanation 👍 @DGM

请先登录,再进行评论。

采纳的回答

DGM
DGM 2021-12-18
编辑:DGM 2024-7-6
When displaying images, imshow(), etc. expect the data to be within a certain range. For floating point data, black is 0, white is 1. For (unsigned) integer data, black is 0, white is the largest value that the integer class can represent. For example, white is 255 for uint8, or 65535 for uint16.
Your image is uint16, but the data only spans 0-4095, so it's rendered as a nearly-black frame. Since the image is RGB, trying to use the displayrange parameter for imshow() (i.e. imshow(myimage,[])) isn't going to work as intended.
If all you want to do is display the image, you can do so a few different ways:
imshow(rescale(A));
or
imshow(mat2gray(A)); % the name is misleading; works fine with RGB
Both of the above will normalize the data to its extrema. The result is a floating-point image in the appropriate range of 0-1 and should display correctly.
If instead of merely displaying it, you wanted to use this as your working image, you could just rescale the image. If your data is arbitrarily-scaled, you might just rescale it with respect to its extrema. This would rescale it to unit-scale float.
% any arbitrary scale --> unit-scale float
B = mat2gray(A);
If instead, you know that your data coming from the camera is uint12-scale, then you should rescale with respect to the dynamic range implied by that scale.
% uint12-scale uint16 --> unit-scale float
B = mat2gray(A,[0 4095]);
If you then wanted the working image to be a particular class other than 'double', you could use im2uint16(), im2uint8(), etc. to cast and rescale the data accordingly.
% uint12-scale uint16 --> native-scale uint16
B = im2uint16(mat2gray(A,[0 4095]));
Alternatively, MIMT imcast() now supports explicit assertion of non-native integer scales. That allows you to convert between any combination of native classes or non-native integer scales.
% uint12-scale uint16 --> native-scale uint16
B = imcast(A,'uint12','uint16');
% uint12-scale uint16 --> native-scale int32
B = imcast(A,'uint12','int32');
% uint12-scale uint16 --> unit-scale float
B = imcast(A,'uint12','double');

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by