当前位置:编程学习 > Matlab >>

帮帮忙 ~!!! DCT算法的matlab程序运行出错 ??? Index exceeds matrix dimensions. Error in ==>

DCT算法的matlab程序运行时提示以下错误 ??? Index exceeds matrix dimensions. Error in ==> Untitled3 at 63 BLOCK2 =J(x:x+K-1,y:y+K-1); 下面是源代码,请高手解答: M=256; %原图像长度 N=32; %水印图像长度 K=8; I=zeros(M,M); II=zeros(K,K); B=zeros(M,M); Idct=zeros(K,K); D=zeros(M,M); %读取原图像 I=imread('e:\wo.png'); subplot(3,2,1); %显示原图像 imshow(I); title('原图像'); %读取水印 J=imread('e:\qianming.png'); subplot(3,2,2); %显示原图像 imshow(J); title('水印图像'); %产生水印序列 randn('seed',10); mark=randn(1024,1); subplot(3,2,4); plot(mark); title('水印序列'); %嵌入水印 T=1; for m=1:N for n=1:N x=(m-1)*K+1; y=(n-1)*K+1; II=I(x:x+K-1,y:y+K-1);%将原图分成8*8的子块 Idct=dct2(II);%对子块进行DCT变换 if x==1&&y==1 alfa=0.002; else alfa=0; end B=Idct*(1+alfa*mark(T));%嵌入水印 Bidct=idct2(B);%进行DCT反变换 D(x:x+K-1,y:y+K-1)=Bidct; T=T+1; end end subplot(3,2,3); imshow(D,[]);%显示嵌入水印后的图像 title('嵌入水印的图像');imwrite(D,'嵌入后的图像.jpg'); %从嵌入水印的图像中提取水印 for p=1:N for q=1:N x=(p-1)*K+1; y=(q-1)*K+1; BLOCK1 =I(x:x+K-1,y:y+K-1); BLOCK2 =J(x:x+K-1,y:y+K-1); BLOCK1=dct2(BLOCK1); BLOCK2=dct2(BLOCK2); a = BLOCK2(1,1)/BLOCK1(1,1)-1; if a<0 W(p,q)=0; else W(p,q)=1; end end end %显示提取的水印 subplot(2,3,2); imshow(W); title('从含水印图像中提取水印');
答案:楼主你的J图像大小是多少?
我测试J的大小是256*256,可以运行,出结果。查看你的图像大小是否是256*256,如果不是的话,K是8,8*8的子块肯定不符合其大小。

上一个:matlab y=(1,:)什么意思
下一个:matlab里面没有tylor函数和nargin函数!~跪求求高手帮忙!!

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,