Convert a PNG to a double matrix

I have a matrix of double type values. I convert it to a PNG with saveas, now I would like to return it back to a double matrix. Is that possible? I understand that a PNG file has 16 billion levels and to convert it back to a double should be possible. If one converts a double matrix to a PNG why cant we work backwards? Larry

1 Kommentar

Larry
Larry am 6 Sep. 2019
Thank you, Walter, it took me 2 years to get back to my question. I appreciate your help. Now, if I get a PNG file and wanted to convert it to a matrix how would I approach that. Not a file I generated, so I do not know where the limits are?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 10 Jul. 2017

0 Stimmen

If the original values you saved were between 0 and 1, then you can use im2double() to get approximations of them back.
If the original values you saved were outside 0 to 1 and were an integer data type, then imread() should have returned the values (though I would need to recheck what happens for negative values in integer data type)
If the original values you saved were outside 0 to 1 and were double(), then most of the data is probably gone, not recoverable.

2 Kommentare

Larry
Larry am 10 Jul. 2017
Walter, Thanks for your response. The original set of data was set between 0-55, using caxis([0 55]), then I used saveas(gca, [opath 'VS',num2str(k),'L',num2str(LL)], 'png') to save it as a PNG file. So, are you saying I will not be able to get my array back since the values are mostly above 1? Larry
Instead of doing that,
filename = sprintf('%sVS%dL%d', opath, k, LL);
ind = im2uint8(mat2gray(YourData, [0 55]);
cmap = colormap();
imwrite(ind, cmap, filename);
Then to recover,
[ind, cmap] = imread(filename);
orig_val = im2double(ind) * 55;

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 10 Jul. 2017

Kommentiert:

am 6 Sep. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by