Problem with .tif images display in matlab
28 ビュー (過去 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 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Convert Image Type についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!