请教两个计算图像信噪比的程序出现的错误
第一个:function =psnr(X,Y)
% function =psnr(X,Y)
% Peak signal to noise ratio of the difference between images and the
mean square error
% If the second input Y is missing then the PSNR and MSE of X itself
becomes the output (as if Y=0).
J=imread('lena.jpg');
X=double(J);
K=imread('lena2.jpg');
Y=double(K);
if nargin<2, D=X;
else
if any(size(X)~=size(Y)), error('The input size is not equal to each
other!'); end
D=X-Y;
end
mse=sum(D(:).*D(:))/prod(size(X));
PSNR=10*log10(255^2/mse);
错误:
??? Error: File: psnr.m Line: 14 Column: 33
A MATLAB string constant is not terminated properly.
第二个:
J=imread('lena.jpg');
I=double(J);
K=imread('lena2.jpg');
I2=double(K);
%I为原始图像,I2为压缩后的图像
Xmean=mean(mean(I))*ones(size(I));
segma2=sum(sum((I-Xmean).^2))/prod(size(I));
D=sum(sum((I-I2).^2))/prod(size(I2));
SNR=10*log10(segma2/D) %%%%%信噪比 (SNR:Signal to Noise Ratio)
PSNR=10*log10(255^2/D) %%%%%峰值信噪比(PSNR:Peak Signal to Noise Ratio)
错误:
??? Error using ==> mtimes
Input arguments must be 2-D.
[ 本帖最后由 eight 于 2008-5-6 09:52 编辑 ] 原帖由 baishui 于 2008-5-5 23:31 发表 http://www.chinavib.com/forum/images/common/back.gif
第一个:
function =psnr(X,Y)
% function =psnr(X,Y)
% Peak signal to noise ratio of the difference between images and the
mean square error
% If the second input Y is missing...
程序写的有点儿乱,找本参考书先看看:@) 原帖由 baishui 于 2008-5-5 23:31 发表 http://www.chinavib.com/forum/images/common/back.gif
第一个:
function =psnr(X,Y)
% function =psnr(X,Y)
% Peak signal to noise ratio of the difference between images and the
mean square error
% If the second input Y is missing... 错误提示都有了,自己根据具体位置检查吧 第一个我没出现错误
第二个错误给你提个醒:
Xmean=mean(mean(I))*ones(size(I));这一句
mean(mean(I))是1x1x3
ones(size(I))是90x90x3(90跟我的图象有关)
eight说的没错,错误提示都出来了,根据位置调试检查就可以.
[ 本帖最后由 laughzha 于 2008-5-6 13:28 编辑 ] 原帖由 laughzha 于 2008-5-6 10:05 发表 http://www.chinavib.com/forum/images/common/back.gif
第一个我没出现错误
第二个错误给你提个醒:
Xmean=mean(mean(I))*ones(size(I));这一句
mean(mean(I))是1x1x3
ones(size(I))是90x90x3(90跟我的图象有关)
eigth说的没错,错误提示都出来了,根据位置调试检查就 ... 第二个错误估计是点运算和矩阵运算的问题,老掉牙的东西了,楼主翻翻 for 新手系列 的帖子吧 好的,感谢院长和laughzha ,我自己再好好学习一下. 第一个调试已经成功发回程序;
function =psnr(X,Y)
% function =psnr(X,Y)
% Peak signal to noise ratio of the difference between images and the mean square error
% If the second input Y is missing then the PSNR and MSE of X itself becomes the output (as if Y=0).
J=imread('lena.jpg');
X=double(J);
K=imread('lena2.jpg');
Y=double(K);
if nargin<2, D=X;
else
if any(size(X)~=size(Y)),
error('The input size is not equal to each other!');
end
D=X-Y;
end
mse=sum(D(:).*D(:))/prod(size(X));
PSNR=10*log10(255^2/mse);
第二个还在思考中,手头没有这方面的书.
页:
[1]