⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.m

📁 神经网络,数字识别,水印程序,matlab 里面有关于matlab数字识别的多份代码及资料
💻 M
字号:
clear; 
%Inputf=imread('lena1.bmp');
Inputf=input('input the images name:','s');
%QF=input('input the para of matrix:');
Inputf=imread(Inputf);
if isrgb(Inputf) 
    Inputf=rgb2gray(Inputf);
end
if isgray(Inputf)  
    Input=double(Inputf);
   [a,b]=size(Inputf);
   %Z(1:a,1:b)=128;
   %Input=Input-Z;
   
subplot(2,2,1);imshow(Inputf,[]);title('原始图象');
%水印信息
block=8;blockno1=fix(a/block);blockno2=fix(b/block);
subplot(2,2,2);file_name='copyright.bmp';
message=double(imread(file_name));
Mm=size(message,1);	                %Height
Nm=size(message,2);	                %Width

% reshape the message to a vector
message=fix(reshape(message,Mm*Nm,1)./2);
message=message(1:blockno1*blockno2);
message=reshape(message,blockno1,blockno2);
 imshow(message);
 title('水印信息');
%量化矩阵
max=[16 11 10 16 24 40 51 61;
     12 12 14 19 26 58 60 55;
     14 13 16 24 40 57 69 56;
     14 17 22 29 51 87 80 62;
    18 22 37 56 68 109 103 77;
    24 35 55 64 81 104 113 92;
   49 64 78 87 103 121 120 101;
   72 92 95 98 112 100 103 99]
%QF=38;
%if QF>=50
    %q=2-0.02*QF;
%else
    %q=50/QF;
%end
%max=round(Q50.*q);
%分块进行DCT变换
for m=1:blockno1
   for n=1:blockno2
      x=(m-1)*block+1;    
      y=(n-1)*block+1;
       mark=message(m,n);
        block_dct1=Input(x:x+block-1,y:y+block-1);
        %block-dct1为DCT系数矩阵
        block_dct1=dct2(block_dct1);
        %量化
       % for i=1:8
          %  for j=1:8
           %     LH(x+i-1,y+j-1)=block_dct1(x+i-1,y+j-1)/max(i,j);
           %end
           %end
           LH=round(block_dct1);
           LHZ=LH./max;
          LH2=LHZ;
       
        %选择水印放置位置
     E=mean2(LHZ(1:6,1:3)) ; 
  %E=abs(mean(E));
    D=sqrt(std2(LHZ(1:6,1:3)));
    %D=sqrt(std(D));
   if mark==0
          LHZ(2,3)=E-D;
      else
          LHZ(2,3)=E+D;
      end
      
      LH1=LHZ.*max;
      LH1=double(LH1);
      block_dct2=idct2(LH1);
      if isa(Inputf,'uint8')
      Outf(x:x+block-1,y:y+block-1)=uint8(block_dct2); 

      elseif isa(Inputf,'uint16')
      Outf(x:x+block-1,y:y+block-1)=uint16(block_dct2);
    
      elseif isa(Inputf,'double')
      Outf(x:x+block-1,y:y+block-1)=block_dct2;
     
      end   
  end
end
subplot(2,2,3);
imshow(Outf,[]);
title('处理后图像');
psnr=check(Outf,Inputf,a,b);
psnr
end


%save test

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -