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

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

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');

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

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

Show 3 older comments

Image Analyst
on 8 Jan 2013

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
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
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.

## 2 Comments

## Walter Roberson (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58221#comment_121345

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

## Sridutt Nayak (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/58221#comment_121349

http://www.filefactory.com/file/6jkza120dkjl/

This has the link to .zip

Thanks