필터 지우기
필터 지우기

Reading a double image

조회 수: 2 (최근 30일)
Andrew
Andrew 2013년 2월 6일
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
close all;
clear all;
fid = fopen('Lenna.out');
m5 = fread(fid, [256, 256], '*double');
fclose(fid);
imagesc(m5),axis off;
colormap(gray);
A = imread('..\Lenna.bmp');
A=double(A);
%PNSR
M = 256;
N = 256;
MSE=0;
for i=1:256
for j=1:256
MSE=MSE+((1/(M*N))*((A(i,j)-m5(i,j)))^2);
end
end
MSE
PSNR = 10*log10(double((255^2)/MSE))
PS: Lenna.out is the decoded image

답변 (1개)

Jan
Jan 2013년 2월 6일
편집: Jan 2013년 2월 6일
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);
  댓글 수: 3
Jan
Jan 2013년 2월 6일
편집: Jan 2013년 2월 6일
It is still not clear how you have written "Lena.out" and "Lena.dat" does not occur in the code you have posted in your question. Did you confuse the .dat with the .out file?
Please copy the error message and mention the line, which causes the error. Check the size of m5 after reading: disp(size(m5)) and explain how Lena.out has been written.
Image Analyst
Image Analyst 2013년 2월 6일
You're writing out uint8s as doubles but didn't convert them. Try this:
count = fwrite(fid,double(A),'*double');

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

카테고리

Help CenterFile Exchange에서 Denoising and Compression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by