问题补充说明:clear all; k=20; %设置水印强度blocksize=8; %设置图像分块为8*8midband=[ 0,0,0,1,1,1,1,0; 0,0,1,1,1,1,0,0; 0,1,1,1,1,0,0,0; 1,1,1,1,0,0,0,0; 1,1,1,0,0,0,0,0; 1,1,0,0,0,0,0,0; 1,0,0,0,0,0,0,0; 0,0,0,0,0,0,0,0 ];message=imread('E:\MATALB\copyright.bmp');%读入图像“copyright”,并转换成双精度数组message=imresize(message,[28,28]);%message=rgb2gray(message);imwrite(message,'copyright.bmp','bmp');figure,imshow(message);message=double(message);Mm=size(message,1); %计算图像的高度Nm=size(message,2); %计算图像的宽度n=Mm*Nm;message=round(reshape(message,1,n*3)./256);%将水印图像转变为1维行向量,message由0,1构成cover_object=imread('E:\MATALB\lena.bmp');%读入原始宿主图像,并转换成双精度数组%cover_object=rgb2gray(cover_object);figure,imshow(cover_object);imwrite(cover_object,'lena.bmp','bmp');cover_object=double(cover_object);Mc=size(cover_object,1); %计算原始宿主图像的高度Nc=size(cover_object,2); %计算原始宿主图像的宽度c=round(Mc/8);d=round(Nc/8);m=c*d; %计算图像划分的图像块xx=1;for j=1:c for i=1:d pjhd(xx)=1/64*sum(sum(cover_object((1+(j-1)*8:j*8),(1+(i-1)*8):i*8))); fc(xx)=1/64*sum(sum((cover_object((1+(j-1)*8:j*8),(1+(i-1)*8):i*8)-pjhd(xx)).^2)); xx=xx+1; endendA=sort(fc); %取出方差最大的前n块B=A((c*d-n+1):c*d); %将水印信息嵌入到方差最大的前n块fc_o=ones(1,c*d);for g=1:n for h=1:c*d if B(g)==fc(h) fc_o(h)=message(g); h=c*d; end endendmessage_vector=fc_o;watermarked_image=cover_object;rand('state',7);pn_sequence_zero=round(rand(1,sum(sum(midband)))); %嵌入水印x=1;y=1;for(kk=1:m) %分块DCT变换 dct_block=dct2(cover_object(y:y+blocksize-1,x:x+blocksize-1)); II=1; if(message_vector(kk)==0) for ii=1:blocksize for jj=1:blocksize if(midband(jj,ii)==1)dct_block(jj,ii)=dct_block(jj,ii)+k*pn_sequence_zero(II); II=II+1; end end end end %分块DCT反变换 watermarked_image(y:y+blocksize-1,x:x+blocksize-1)=idct2(dct_block); if(x+blocksize)>=Nc x=1;y=y+blocksize; else x=x+blocksize; endendwatermarked_image_int=uint8(watermarked_image);%生成并输出潜入水印后的图像imwrite(watermarked_image_int,'dct2_watermarked.bmp','bmp');%显示峰值信噪比xsz=255*255*Mc*Nc/sum(sum((cover_object-watermarked_image).^2));psnr=10*log10(xsz)%显示嵌入水印后的图像figure;imshow(watermarked_image_int,[])title('Watermarked Image')索引超出矩阵维度。因为毕业设计选了专业不对口的老师,所以对MATLAB真的是一窍不通 也不知道哪里错了 只能求救网友了 求各路大神给个改的方法。报错只有一个索引超出矩阵维度。
line确实被我定位变量了,因为我要读取文件中的数据是一行行读的,
1通控看刑毫-7是因为我读出的数360问答据是1行7列,
2:8意思是我从line这一行中的第2列读到第8列,读出来的数据,我暂时让他以字符显示,(我换成数据显示也出现同样的错误)
标签:matlab2,维度,索引