声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 809|回复: 2

[编程技巧] 峰值信噪比程序出错,求指点

[复制链接]
发表于 2008-5-23 10:04 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
以下两个程序都有点问题 希望高手指点以下:
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,mse]=psnr(X,Y)
% function [PSNR,mse]=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 编辑 ]
回复
分享到:

使用道具 举报

发表于 2008-5-23 10:30 | 显示全部楼层
...高手不是神仙啊,把你的程序背景稍微描述一下吧。
 楼主| 发表于 2008-5-23 11:36 | 显示全部楼层
啊 我会了 弄好了。。 谢谢 啊 呵呵
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-6-17 09:13 , Processed in 0.069874 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表