matlab的小波水印程序报错 这是另一个程序 达人帮忙看看啊 10
废话不多说上程序:%读入原始宿主图像file_name='lena.bmp';cover_object=double(imread(file_name));Mc=size...
废话不多说 上程序:
%读入原始宿主图像
file_name='lena.bmp';
cover_object=double(imread(file_name));
Mc=size(cover_object,1); %计算图像的高度
Mc=size(cover_object,2); %计算图像的宽度
%读入二值水印图像
file_name='sdnu.bmp';
message=double(imread(file_name));
Mm=size(message,1);
Nm=size(message,2);
[ca,ch,cv,cd]=dwt2(cover_object,'haar');%一级Haar小波变换
ca1=ca;
Mg=size(ca,1);
Mk=size(ca,2);
%这段有错!!!!!!!!!!
for i=1:Mg
for j=1:Mk
if(message(i,j)==0)
ca1(i,j)=ca(i,j)+1;
end
end
end
watermarked_image=idwt2(ca1,ch,cv,cd,'haar');
watermarked_image_round=round(watermarked_image);
watermarked_image_uint8=uint8(watermarked_image_round);
%生成并输出嵌入水印后的图像
figure(1)
imshow(watermarked_image_uint8,[]);
title('Watermarked Image')
imwrite(watermarked_image_uint8,'dwt_watermarked.bmp','bmp');
%计算峰值性噪比
xsz=200*200*max(max(cover_object.^2))/sum(sum((cover_object-watermarked_image_round).^2));
psnr=10*log10(xsz);
for i=1:Mg
for j=1:Mk
if(message(i,j)==0)
ca1(i,j)=ca(i,j)+1;
end
end
end
报错:??? Index exceeds matrix dimensions.
我知道意思大概是数行数列数数过了 可是本人无奈matlab刚刚学,不知道怎么修改,麻烦达人给帮帮看看!!万分感谢,把我所有的分都给你,不好意思我就这点分了。肯定是同行,如不嫌弃交个朋友,我的qq:45514223.
还有一个也有错:
%计算开始时间
start_time=cputime;
%载入宿主图像
file_name='lena.bmp';
p=imread(file_name);
%获得宿主图像的宽和高
x=double(imread(file_name));
mc=size(x,1);
nc=size(x,2);
%对宿主图像进行三层小波分解
[ca1,ch1,cv1,cd1]=dwt2(x,'haar');
[ca2,ch2,cv2,cd2]=dwt2(ca1,'haar');
[ca3,ch3,cv3,cd3]=dwt2(ca2,'haar');
%载入原始水印
file_name='sdnu.bmp';
q=imread(file_name);
%显示原始的水印
figure(1)
imshow(q),title('原始水印');
%获得水印的宽和高
y=double(imread(file_name));
mo=size(y,1);
no=size(y,2);
%对水印进行一层小波分解
[ca5,ch5,cv5,cd5]=dwt2(y,'haar');
%嵌入水印 这一段有错!!!!!!!!!!
ch3(17:48,17:48)=ch3(17:48,17:48)+0.1*cd5;
cv3(17:48,17:48)=cv3(17:48,17:48)+0.1*ca5;
ch1(97:128,97:128)=ch1(97:128,97:128)+0.1*ch5;
cv2(33:64,33:64)=cv2(33:64,33:64)+0.1*ca5;
cv1(97:128,97:128)=cv1(97:128,97:128)+0.1*ca5;
ch2(33:64,33:64)=ch2(33:64,33:64)+0.1*cv5;
%重构图像
w1=idwt2(ca3,ch3,cv3,cd3,'haar');
w2=idwt2(w1,ch2,cv2,cd2,'haar');
w3=idwt2(w2,ch1,cv1,cd1,'haar');
%将嵌入水印的图像写到文件中
w43_uint8=uint8(w3);
imwrite(w43_uint8,'dwt3_watermarked.bmp','bmp');
w43_uint8=uint8(w3);
%计算峰噪比
psnr=PSNR(x,w43_uint8)
%归一化互相关系数
cq=CQ(x,w43_uint8)
s=imread('dwt3_watermarked.bmp');
%b=imresize(s,0.5);
figure(2)
%imshow(b)
subplot(1,2,1),
imshow(s);
title('嵌入有水印的图像');
subplot(1,2,2),
imshow(p)
title('宿主图像');
出错处已标上了,报错为:??? Error using ==> plus
Matrix dimensions must agree.
这个也顺便看看把!!多谢各位大哥大姐!
亲爱的们,我希望得到修改,不只是指出错误哦,错误语句我已经很清楚标上了! 展开
%读入原始宿主图像
file_name='lena.bmp';
cover_object=double(imread(file_name));
Mc=size(cover_object,1); %计算图像的高度
Mc=size(cover_object,2); %计算图像的宽度
%读入二值水印图像
file_name='sdnu.bmp';
message=double(imread(file_name));
Mm=size(message,1);
Nm=size(message,2);
[ca,ch,cv,cd]=dwt2(cover_object,'haar');%一级Haar小波变换
ca1=ca;
Mg=size(ca,1);
Mk=size(ca,2);
%这段有错!!!!!!!!!!
for i=1:Mg
for j=1:Mk
if(message(i,j)==0)
ca1(i,j)=ca(i,j)+1;
end
end
end
watermarked_image=idwt2(ca1,ch,cv,cd,'haar');
watermarked_image_round=round(watermarked_image);
watermarked_image_uint8=uint8(watermarked_image_round);
%生成并输出嵌入水印后的图像
figure(1)
imshow(watermarked_image_uint8,[]);
title('Watermarked Image')
imwrite(watermarked_image_uint8,'dwt_watermarked.bmp','bmp');
%计算峰值性噪比
xsz=200*200*max(max(cover_object.^2))/sum(sum((cover_object-watermarked_image_round).^2));
psnr=10*log10(xsz);
for i=1:Mg
for j=1:Mk
if(message(i,j)==0)
ca1(i,j)=ca(i,j)+1;
end
end
end
报错:??? Index exceeds matrix dimensions.
我知道意思大概是数行数列数数过了 可是本人无奈matlab刚刚学,不知道怎么修改,麻烦达人给帮帮看看!!万分感谢,把我所有的分都给你,不好意思我就这点分了。肯定是同行,如不嫌弃交个朋友,我的qq:45514223.
还有一个也有错:
%计算开始时间
start_time=cputime;
%载入宿主图像
file_name='lena.bmp';
p=imread(file_name);
%获得宿主图像的宽和高
x=double(imread(file_name));
mc=size(x,1);
nc=size(x,2);
%对宿主图像进行三层小波分解
[ca1,ch1,cv1,cd1]=dwt2(x,'haar');
[ca2,ch2,cv2,cd2]=dwt2(ca1,'haar');
[ca3,ch3,cv3,cd3]=dwt2(ca2,'haar');
%载入原始水印
file_name='sdnu.bmp';
q=imread(file_name);
%显示原始的水印
figure(1)
imshow(q),title('原始水印');
%获得水印的宽和高
y=double(imread(file_name));
mo=size(y,1);
no=size(y,2);
%对水印进行一层小波分解
[ca5,ch5,cv5,cd5]=dwt2(y,'haar');
%嵌入水印 这一段有错!!!!!!!!!!
ch3(17:48,17:48)=ch3(17:48,17:48)+0.1*cd5;
cv3(17:48,17:48)=cv3(17:48,17:48)+0.1*ca5;
ch1(97:128,97:128)=ch1(97:128,97:128)+0.1*ch5;
cv2(33:64,33:64)=cv2(33:64,33:64)+0.1*ca5;
cv1(97:128,97:128)=cv1(97:128,97:128)+0.1*ca5;
ch2(33:64,33:64)=ch2(33:64,33:64)+0.1*cv5;
%重构图像
w1=idwt2(ca3,ch3,cv3,cd3,'haar');
w2=idwt2(w1,ch2,cv2,cd2,'haar');
w3=idwt2(w2,ch1,cv1,cd1,'haar');
%将嵌入水印的图像写到文件中
w43_uint8=uint8(w3);
imwrite(w43_uint8,'dwt3_watermarked.bmp','bmp');
w43_uint8=uint8(w3);
%计算峰噪比
psnr=PSNR(x,w43_uint8)
%归一化互相关系数
cq=CQ(x,w43_uint8)
s=imread('dwt3_watermarked.bmp');
%b=imresize(s,0.5);
figure(2)
%imshow(b)
subplot(1,2,1),
imshow(s);
title('嵌入有水印的图像');
subplot(1,2,2),
imshow(p)
title('宿主图像');
出错处已标上了,报错为:??? Error using ==> plus
Matrix dimensions must agree.
这个也顺便看看把!!多谢各位大哥大姐!
亲爱的们,我希望得到修改,不只是指出错误哦,错误语句我已经很清楚标上了! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询