Reading a double image
12 views (last 30 days)
I have encoded and decoded a 256*256 image. At first i did it using the image in "*uint8" precision and everything works well. but when i change uint8 to "double", i get an error while finding the MSE of the image. the error says that the decoded image is of size [256 33]. please look at my code and advice if there is a mistake am making here.
% Read the contents back into an array
fid = fopen('Lenna.out');
m5 = fread(fid, [256, 256], '*double');
A = imread('..\Lenna.bmp');
M = 256;
N = 256;
PSNR = 10*log10(double((255^2)/MSE))
PS: Lenna.out is the decoded image
Jan on 6 Feb 2013
Edited: Jan on 6 Feb 2013
You can read a file in binary format only in the format it has been written in. When you have written Lena.out as UINT8 values, you cannot read it in double precision. So please show us how the file has been created.
It is surprinsing that the imported data have the size [256 x 33]. When it would be [256 x 32] I'd assume, that you have simply read the file, which contains 256*256 bytes (UINT8 values) as doubles, which need 8 bytes per element: 8*32=256. But where could the 33.th column come from? How did you encounter the size of the matrix?
I guess you want:
m5 = fread(fid, [256, 256], 'uint8'); % Now m5 has the type double!
m5 = m5 / 255;
And finally without an expensive loop:
MSE = sum((A(:)-m5(:)) .^ 2) / (M*N);