imwrite and imread are not giving the same matrix
Afficher commentaires plus anciens
Hello,
I want to show a matrix in an image (and save it for later use) and then retrieve the matrix from that image using imread. I followed the approach presented in https://www.mathworks.com/matlabcentral/answers/242747-how-can-i-convert-a-matrix-with-decimal-values-into-a-image-and-then-retrieve-the-same-matrix-back-f
However, while saving the image with the command imwrite, and then later read it with imread, I see two different matrices. Here is what I have done:
clear all, close all, clc
% A=rand(10); %random matrix(10x10) with values between 0 to 1.
% B=A*150;
B = [3 1; 2 5];
sz = size(B);
R = typecast(uint64(B(:) * 2^56),'uint8');
R1 = reshape(R, [8 sz]);
R2 = permute(flipud(R1), [2 3 1 4]);
R3 = reshape(R2, [sz(1), sz(2)*8, 1]);
imshow(R3);
imwrite(R3, 'TestFile.jpg')
close all
A = imread('TestFile.jpg');
sz = size(A);
U3 = reshape(A, [sz(1), sz(2)/8, 8, 1]);
U2 = flipdim(permute(U3, [3 1 2 4]),1);
UB = reshape(double(typecast(U2(:), 'uint64')) / 2^56, [sz(1), sz(2)/8, 1]);
Now my question is how to get the correct matrix from imread.
Thank you.
Khalid
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Convert Image Type dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!