how can save gray scale image without loss information ?

조회 수: 2 (최근 30일)
K. Taieb
K. Taieb 2020년 5월 20일
답변: Image Analyst 2020년 5월 21일
Hello,
I converted a matrix to a grayscale image.
I saved the image with imwrite
I read the image with imread
The data obtained (uint8) between 0 and 255. in order to convert them to double (0,1) I used im2double.
The result obtained (I3) is a little different to the initial data (I). Is it possible to avoid this error and obtain the same result (I3 = I)?
Thank you
A =[0 200 400 600; 800 1000 1200 1400;1600 1800 2000 2200];
Amin=min(min(A));
Amax=max(max(A));
I=mat2gray(A,[Amin Amax]);
imwrite(I,'NewFile.png')
I2=imread('NewFile.png');
I3= im2double(I2);
isequal(I,I3)

답변 (2개)

darova
darova 2020년 5월 20일
Try this
  댓글 수: 5
darova
darova 2020년 5월 20일
Maybe you can't? Hm, i don't know
K. Taieb
K. Taieb 2020년 5월 20일
Thanks :)

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2020년 5월 21일
I never use im2double(). If it's double, just use it as double. If it's integer and you want double, just use double(). If you want to store as double, use save() and save it to a .mat file. If you want an integer file so you have nice little icons in File Explorer, cast to uint16 or uint8. If the number is beyond those ranges, you can use rescale() or mat2gray() to scale the data before casting to integer.

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by