Problem with .tif images display in matlab

조회 수: 37 (최근 30일)
Rohit Thokala
Rohit Thokala 2021년 12월 18일
편집: DGM 2024년 7월 6일
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