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

1 view (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 8 Jan 2013
Without looking at your data, the most obvious possibility would be that the version that saturates is dataclass double instead of uint8
  6 Comments
Walter Roberson
Walter Roberson on 8 Jan 2013
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 on 8 Jan 2013
Edited: Image Analyst on 8 Jan 2013
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type 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!