1.
clear all;
d=0;
e=0;
file_name='lena.bmp';
%读取原图像
cover_object=double(imread(file_name));
Mc=size(cover_object,1);
%原图像行数
Nc=size(cover_object,2);
%原图像列数
file_name='attacked_image1.bmp';
watermarked_image=double(imread(file_name));
%计算信噪比
for i=1:Mc
for j=1:Nc
a(i,j)=cover_object(i,j)^2;
b(i,j)=cover_object(i,j)-watermarked_image(i,j);
d=d+a(i,j);
e=e+b(i,j)^2;
end
end
psrn=10*log10(d/e)
2.
%Name:Chris Shoemaker
%Course: EER-280 - Digital Watermarking
%Project:Calculates the PSNR (Peak Signal to Noise Ratio)
%
of images A and A', both of size MxN
function [A] = psnr(image,image_prime,M,N)
% convert to doubles
image=double(image);
image_prime=double(image_prime);
% avoid divide by zero nastiness
if ((sum(sum((image-image_prime).^2))) == 0)
error('Input vectors must not be identical')
else
psnr_num=M*N*max(max(image_prime.^2));
% calculate numerator
psnr_den=sum(sum((image-image_prime).^2));
% calculate denominator
A=psnr_num/psnr_den;
% calculate PSNR
end
return
3.%Name:Chris Shoemaker
%Course: EER-280 - Digital Watermarking
%Project:Calculates the PSNR (Peak Signal to Noise Ratio)
%
of images A and A', both of size MxN
function [A] = psnr(image,image_prime,M,N)
% convert to doubles
image=double(image);
image_prime=double(image_prime);
% avoid divide by zero nastiness
if ((sum(sum((image-image_prime).^2))) == 0)
error('Input vectors must not be identical')
else
psnr_num=M*N*max(max(image_prime.^2));
% calculate numerator
psnr_den=sum(sum((image-image_prime).^2));
% calculate denominator
A=psnr_num/psnr_den;
% calculate PSNR
end
return
4.
clear all;
d=0;
e=0;
file_name='lena.bmp';
%读取原图像
cover_object=double(imread(file_name));
Mc=size(cover_object,1);
%原图像行数
Nc=size(cover_object,2);
%原图像列数
file_name='attacked_image1.bmp';
watermarked_image=double(imread(file_name));
%计算信噪比
for i=1:Mc
for j=1:Nc
a(i,j)=cover_object(i,j)^2;
b(i,j)=cover_object(i,j)-watermarked_image(i,j);
d=d+a(i,j);
e=e+b(i,j)^2;
end
end
psrn=10*log10(d/e)
这几个峰值信噪比公式对不比如我的原图像123.jpg和生成图像1234jpg放在那里合适,请赐教
回 2楼
|
错误:函数定义是不允许在提示符下或在脚本中。
??? function [A] = psnr('lena04.jpg','lena05.jpg',M,N)
|
Error: Function definitions are not permitted at the prompt or in scripts.
老是这句话 function这个也不对哦
|