how can save gray scale image without loss information ?

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 日

1 投票

Try this

5 件のコメント

K. Taieb
K. Taieb 2020 年 5 月 20 日
Thank you
It's the same problem
darova
darova 2020 年 5 月 20 日
編集済み: darova 2020 年 5 月 20 日
THere is a difference (small), indeed
>> A/max(A(:))*255
ans =
0 23.1818 46.3636 69.5455
92.7273 115.9091 139.0909 162.2727
185.4545 208.6364 231.8182 255.0000
I think it's because imread or imwrite rounds the data
A =[0 200 400 600; 800 1000 1200 1400;1600 1800 2000 2200];
A1 = A/max(A(:));
imwrite(A1,'im.png')
A2 = imread('im.png');
A3 = im2double(A2);
imagesc(A3-A1)
colorbar
K. Taieb
K. Taieb 2020 年 5 月 20 日
Thank you
yes I think too imwrite rounds the data.
Just how I can find the matrix A from the saved image im?
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 日

1 投票

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.

カテゴリ

ヘルプ センター および File ExchangeImages についてさらに検索

質問済み:

2020 年 5 月 20 日

回答済み:

2020 年 5 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by