声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1898|回复: 1

快答辩了,求助基于离散余弦变换的数字水印matlab仿真源码

[复制链接]
发表于 2006-5-29 10:00 | 显示全部楼层 |阅读模式

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

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

x
<P>各位兄弟姐妹,小弟跪求如题所示源代码!若有高手也帮小弟调试一下程序,不胜感激!从水印提取以后就运行不好~~若有好的建议发到我邮箱:<a href="mailteagle217@tom.com    target="_blank" >eagle217@tom.com      真诚感谢<BR></A><BR><BR><BR> %读入原始图像,设置参数<BR>trueImage=imread('hua.jpg');<BR>trueImage=rgb2gray(trueImage);<BR>alfa=.1;LENGTH=2500;<BR>subplot(2,2,1);<BR>imshow(trueImage);<BR>title('original image');</P>
<P><BR>%对原图像进行DCT变换<BR>dctF1=dct2(trueImage);<BR>subplot(2,2,2);<BR>imshow(log(abs(dctF1)),[]);<BR>title('DCT coefficient matrix');<BR>[m,n]=size(dctF1);</P>
<P><BR>%产生水印序列并对其进行排序<BR>randn('state',10);<BR>waterMark1=randn(LENGTH,1);<BR>subplot(2,2,3);<BR>plot(waterMark1);<BR>title('watermark sequence');<BR>[Y0,I0]=sort(waterMark1);</P>
<P><BR>%找出水印嵌入位置(幅值较大的n个频域成分)<BR>A=dctF1(:);<BR>[Y1,I1]=sort(A);<BR>x=m*n;<BR>k=LENGTH;<BR>M=zeros(x,1);<BR>%修改幅值较大的n个频域成分的幅值,嵌入水印<BR>for i=1:x<BR>    if k&gt;=1<BR>       M(x)=Y1(x)*(1+alfa*Y0(k));<BR>        k=k-1;<BR>    else<BR>        M(x)=Y1(x);<BR>    end<BR>    x=x-1;<BR>end<BR>N=zeros(x,1);<BR>x=m*n;<BR>for  i=1:x<BR>     N(I1(i))=M(i);<BR>end<BR>a=1;<BR>for  j=1:n,<BR>     for  i=1:m,<BR>          dctF2(i,j)=N(a);<BR>          a=a+1;<BR>     end<BR>end<BR>%DCT 反变换,得到嵌入水印的图像<BR>idctF1=idct2(dctF2);<BR>subplot(2,2,4);<BR>imshow(idctF1,[]);<BR>title('embedded image');</P>

<P>%水印提取逆过程是嵌入过程的逆过程<BR>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function watermark_detect(image,Y1,I0,waterMark1)<BR>%image:嵌入水印的图像<BR>%Y1:原始图像的序列排序<BR>%I0:原始水印的排列序号<BR>%waterMark1):原始水印序列<BR>%对嵌入水印图像进行DCT变换<BR>dctW1=dct2(image);<BR>%找出幅值较大的系数<BR>B=dctW1(1);<BR>[Y2,I2]=sort(B);<BR>[m1,n1]=size(dctW1);<BR>y=m1*n1;<BR>k=length(waterMark1);<BR>N0=zeros(k,1);<BR>%提取水印序列<BR>while  k&gt;=1<BR>       N0(k)=(Y2(y)-Y1(y))/alfa/Y1(y);<BR>       k=k-1;<BR>       y=y-1;<BR>end<BR>k=length(waterMark1);<BR>waterMark2=zeros(k,1);<BR>for    i=1:k<BR>       waterMark2(I0(i))=N0(i);<BR>end<BR>%选取50个测试序列,其中第10个位提取出的水印<BR>figure;<BR>for    i=1:50<BR>       if  i==10<BR>           waterMark=waterMark2;<BR>       else<BR>           waterMark=rand(k,1);<BR>end<BR>%计算各个序列与原水印序列的相关值<BR>c=waterMark'*waterMark1/sqrt(waterMark'*watermark);<BR>stem(i,c);<BR>hold on;<BR>end<BR>%攻击实验<BR>disp('input your choice according to the following image processing operation:');<BR>disp('0--exit'); <BR>disp('1--smoothing patterns');<BR>disp('2--adding uniform noise');%添加噪声<BR>disp('3--adding fiter [10,10]');%滤波 <BR>disp('4--cutting part of the image');%剪切<BR>disp('5--10 quality JPEG compression');%压缩<BR>disp('6--rotate 45');%旋转<BR> </P>
<P>d=input('please input your choice:')<BR>while d~=0<BR>switch d<BR>case 1<BR>watermark_detect(idctF1,Y1,I0,waterMark1);<BR>case 2<BR>    WImage2=idctF1;<BR>    noise0=10*rand(size(WImage2));<BR>    WImage2=WImage2+noise0;<BR>    figure;<BR>inshow(WImage2,[]);<BR>title('adding uniform noise');<BR>watermark_detect(WImage2,Y1,I0,waterMark1);<BR>case 3<BR>WImage3=idctF1;<BR>H=fspecial('gaussian',[10,10]');<BR>WImage3=imfilter(WImage3,H);<BR>figure;<BR>imshow(WImage,[]);<BR>title('through filter [10,10]');<BR>watermark_detect(WImage3,Y1,I0,waterMark1);<BR>case 4<BR>WImage4=idctF1;<BR>WImage4(1:128,1:128)=256;<BR>figure;<BR>imshow(WImage4);<BR>title('cutting part of the image');<BR>watermark_detect(WImage4,Y1,I0,waterMark1);<BR>case 5<BR>Wimage5=idctF1;<BR>Wimage5=im2double(WImage5);<BR>cnum=10;<BR>dctm=dctmtx(8);<BR>P1=dctm;<BR>P2=dctm.';<BR>imageDCT=blkproc(WImage5,[8,8],'P1*x*P2'dctm,dctm.');<BR>DCTvar=im2col(imageDCT,[8,8],'distinct').';<BR>n=size(DCTvar,1);<BR>DCTvar=(sum(DCTvar.*DCTvar)-(sum(DCTvar)/n).^2)/n;<BR>[dum,order]=sort(DCTvar);<BR>cnum=64-cnum;<BR>mask=ones(8,8);<BR>mask(order(1:cnum))=zeros(1,cnum);<BR>im88=zeros(9,9);<BR>im88(1:8,1:8)=mask;<BR>im128128=kron(im88(1:8,1:8),ones(16));<BR>dctm=dctmtx(8);<BR>P1=dctm.';<BR>P2=mask(1;8,1:8);<BR>P3=dctm;<BR>WImage5=blkproc(imageDCT,[8,8],'P1*(x.*P2)*P3',dctm.',mask(1:8,1:8),dctm);<BR>figure;<BR>imshow(WImage5);<BR>title('JPEG Image');<BR>watermark_detect(WImage5,Y1,I0,waterMark1);<BR>case 6<BR>WImage6=idctF1;<BR>WImage6=imrotate(WImage,45,'bilinear','crop');<BR>figure;<BR>imshow(WImage6);<BR>title('rotate 45');<BR>watermark_detect(WImage6,Y1,I0,waterMark1);<BR>case 0<BR>    break;<BR>otherwise <BR>    error('you have input a valid value');<BR> end<BR>d=input('please input your choice:');<BR>end  <BR>    <BR></P>
回复
分享到:

使用道具 举报

发表于 2006-5-29 11:33 | 显示全部楼层

回复:(eagle217)快答辩了,求助基于离散余弦变换的...

最好先把出现的问题说明一下
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-11-20 09:34 , Processed in 0.068994 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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