MATLAB Answers


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

Asked by Sridutt Nayak on 8 Jan 2013

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');
Sum_of_abs_diff = sum(sum(abs(B1-B2)))
Max_Diff = max(max(B1-B2))
%Both are Zero
close all;

All code and data with images are here. Run Test.m


I do not know what a .zipx file is, but I would not expect that I can read it on my system.

1 Answer

Answer by Walter Roberson
on 8 Jan 2013
 Accepted answer

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


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.

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.

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.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!