声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1295|回复: 6

[编程技巧] 请教两个计算图像信噪比的程序出现的错误

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

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

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

x
第一个:
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).
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 编辑 ]
回复
分享到:

使用道具 举报

发表于 2008-5-6 06:54 | 显示全部楼层
原帖由 baishui 于 2008-5-5 23:31 发表
第一个:
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  ...


程序写的有点儿乱,找本参考书先看看:@)
发表于 2008-5-6 09:52 | 显示全部楼层
原帖由 baishui 于 2008-5-5 23:31 发表
第一个:
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  ...
错误提示都有了,自己根据具体位置检查吧
发表于 2008-5-6 10:05 | 显示全部楼层
第一个我没出现错误
第二个错误给你提个醒:
Xmean=mean(mean(I))*ones(size(I));这一句
mean(mean(I))是1x1x3
ones(size(I))是90x90x3(90跟我的图象有关)

eight说的没错,错误提示都出来了,根据位置调试检查就可以.

[ 本帖最后由 laughzha 于 2008-5-6 13:28 编辑 ]

评分

1

查看全部评分

发表于 2008-5-6 10:08 | 显示全部楼层
原帖由 laughzha 于 2008-5-6 10:05 发表
第一个我没出现错误
第二个错误给你提个醒:
Xmean=mean(mean(I))*ones(size(I));这一句
mean(mean(I))是1x1x3
ones(size(I))是90x90x3(90跟我的图象有关)

eigth说的没错,错误提示都出来了,根据位置调试检查就 ...
第二个错误估计是点运算和矩阵运算的问题,老掉牙的东西了,楼主翻翻 for 新手系列 的帖子吧
 楼主| 发表于 2008-5-6 11:37 | 显示全部楼层
好的,感谢院长和laughzha ,我自己再好好学习一下.
 楼主| 发表于 2008-5-6 14:31 | 显示全部楼层
第一个调试已经成功发回程序;
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).
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);
第二个还在思考中,手头没有这方面的书.
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-9-23 11:15 , Processed in 0.056978 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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