Imshow saturating though the pixel-by-pixel data is same

I've a text file with ',' delimiter with the data from the image in memory.
I have parsed it to get a Matrix then an image after converting the data to uint8. I have the same image taken with other API's.
The data read by both pixel-by-pixel looks same but display saturates at high intensity areas. i.e Display is different even though sum(sum(abs(Mat1-Mat2))) = 0
M = textread('alphabet.txt','%d','delimiter',',');
B1 = vec2mat(M); %Converts the column vector to 1280X1024 Matrix (See link for actual fn)
B1 = uint8(B1);
B2 = imread('Test.bmp');
subplot(1,2,1)
imshow(B1);
subplot(1,2,2)
imshow(B2);
Sum_of_abs_diff = sum(sum(abs(B1-B2)))
Max_Diff = max(max(B1-B2))
%Both are Zero
pause(2)
close all;
end
All code and data with images are here. Run Test.m

2 件のコメント

Walter Roberson
Walter Roberson 2013 年 1 月 8 日
I do not know what a .zipx file is, but I would not expect that I can read it on my system.
Sridutt Nayak
Sridutt Nayak 2013 年 1 月 8 日
This has the link to .zip
Thanks

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2013 年 1 月 8 日

0 投票

Without looking at your data, the most obvious possibility would be that the version that saturates is dataclass double instead of uint8

6 件のコメント

Sridutt Nayak
Sridutt Nayak 2013 年 1 月 8 日
I have added link to .zip file for data and images. Also is there a work around for it?
Walter Roberson
Walter Roberson 2013 年 1 月 8 日
Your code has
Max_Diff = max(max(B1-B2))
but at each location B1 <= B2 and you failed to look for a minimum. If you had looked for a minimum you would have been caught by the fact that you are subtracting two uint8 and the minimum representable in uint8 is 0, so you would not have been detecting when B1 < B2 anyhow.
Adjusted code:
Max_Diff = max(abs(double(B1(:))-double(B2(:))));
Sridutt Nayak
Sridutt Nayak 2013 年 1 月 8 日
Ah!! That explains why I was thinking that the images were same..
To remove saturation, I added 255 for the values < 0
Image Analyst
Image Analyst 2013 年 1 月 8 日
編集済み: Image Analyst 2013 年 1 月 8 日
I don't see how that makes sense. Why not use the formula Walter gave? By the way, in his top Answer, I believe he meant "that saturates is dataclass uint8 instead of double". You will get all zeros if B2 is brighter than B1 for all pixels.
Walter Roberson
Walter Roberson 2013 年 1 月 8 日
My original thought was that data in the range 0-255 had been converted to double(), in which case imshow would treat everything from 1 upward as full white.
Image Analyst
Image Analyst 2013 年 1 月 8 日
編集済み: Image Analyst 2013 年 1 月 8 日
Ah! You meant that imshow() saturates values greater than 1 to white, rather than subtracting uint8s saturating at zero if they would go negative. I understand. But I still don't understand why, after Sridutt casts to doubles and can get negative numbers, why he adds 255 to only those numbers that are negative. That is bizarre.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDisplay Image についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by