Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Images saved in png are completely different with what I get from using images

조회 수: 1 (최근 30일)
Golnoush Asaeikheybari
Golnoush Asaeikheybari 2019년 5월 17일
마감: MATLAB Answer Bot 2021년 8월 20일
I have two matrixes which the pixel value of one of them is 0, 1, ,2, 3. When I save them with the code below I get a copmletely black image while I can see the image as below when I use imagesc in matlab to see the image.
destdirectory = '/Users/good';
%mkdir(destdirectory); %create the directory
thisimage = 'first.png';
fulldestination = fullfile(destdirectory, thisimage); %name file relative to that directory
imwrite(IMG, fulldestination);
for another image, the pixel values include NaN, 0, 3, 2.12334 and I saw the image that is saved is completely differnt with what I see when I use imagesc. The first image below is what I see by imagesc and the second one is what I see after I save it. I am intersted to save it exactly as I see in imagesc.
Thank you for your help.
  댓글 수: 1
Stephen23
Stephen23 2019년 5월 21일
편집: Stephen23 2019년 5월 21일
"I have two matrixes which the pixel value ..."
Please upload the two matrices in one mat file, by clicking the paperclip button.

답변 (1개)

Prathamesh Degwekar
Prathamesh Degwekar 2019년 5월 21일
Hi,
When you write an image in the "png" format, the data in it changes for the sake of compression, etc. Thus the data in it is different.
Imagesc looks at the data and displays it as a colourmap, as explained in the link below.
Thus the data stored in the two files/matrices would be different due to the changes that the "png" file format requires.
If you want to save it exactly as you see it, try using bitmap ("bmp") file format or "raw" format to store your image.
Hope this helps.
Cheers.
  댓글 수: 1
Stephen23
Stephen23 2019년 5월 21일
편집: Stephen23 2019년 5월 21일
"When you write an image in the "png" format, the data in it changes for the sake of compression, etc. Thus the data in it is different."
PNG is a lossless compression format.
Pre-processing of the data can occur, before it is saved.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by