MATLAB: IMWRITE followed by IMREAD Changes Pixel Values

imageimage processing

I have an image matrix
aa 150x200x3 720000 double
With pixel values 0-255
Why does this test fail :
imwrite(aa, 'aatest.png');
aanew = imread('aatest.png');
isequal(aa, aanew)

Best Answer

I tried this, and I realized that ISEQUAL compares a DOUBLE and UINT8, which quite obviously does not return true.
p = rand(150,200,3);
imwrite(p,'test.png');
pnew = imread('test.png');
isequal(p,pnew)
if you really want to check equality,
isequal(im2uint8(p),pnew)
is the way to go.