buttle 发表于 2008-5-23 10:04

峰值信噪比程序出错,求指点

以下两个程序都有点问题 希望高手指点以下:
function dPSNR = psnr(ImageA,ImageB)

if (size(ImageA,1) ~= size(ImageB,1)) or (size(ImageA,2) ~= size(ImageB,2))
    error('ImageA <> ImageB');
    dPSNR = 0;
    return ;
end
ImageA=double(ImageA);
ImageB=double(ImageB);
M = size(ImageA,1);
N = size(ImageA,2);
   
d = 0 ;
for i = 1:M
    for j = 1:N
      d = d + (ImageA(i,j) - ImageB(i,j)).^2 ;
    end
end

dPSNR = 10*log10((M*N*max(max(ImageA.^2)))/d) ;

return

Error in ==> psnr2 at 3
if (size(ImageA,1) ~= size(ImageB,1)) or (size(ImageA,2) ~= size(ImageB,2))
-------------------------------------------------------------------------------------------------------------------

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).

if nargin<2, D=X;
else
if any(size(X)~=size(Y)), error('The input size is not equal to each other');
end
X=double(X);
Y=double(Y);
D=X-Y;
end

mse=sum(D(:).*D(:))/prod(size(X));
PSNR=10*log10(255^2/mse);

Error in ==> psnr at 6
if nargin<2, D=X;

[ 本帖最后由 buttle 于 2008-5-23 10:08 编辑 ]

sogooda 发表于 2008-5-23 10:30

...高手不是神仙啊,把你的程序背景稍微描述一下吧。

buttle 发表于 2008-5-23 11:36

啊 我会了 弄好了。。 谢谢 啊 呵呵
页: [1]
查看完整版本: 峰值信噪比程序出错,求指点