IMWRITE followed by IMREAD Changes Pixel Values

조회 수: 1 (최근 30일)
Ajmal
Ajmal 2013년 8월 19일
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)

채택된 답변

Amith Kamath
Amith Kamath 2013년 8월 19일
편집: Amith Kamath 2013년 8월 19일
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.

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 8월 19일
I don't believe PNG is meant for doubles, though I could be wrong. Anyway I never try to save color images while in a double class unless it's to a mat file. Try casting your aa array to uint8 before you save it out. I think that's really what you want and intended anyway.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by