www.pudn.com > Watermark.rar > Arnold.m, change:2009-06-25,size:1318b


function im=Arnold(img,IP,M,X,Y) 
 
% img=double(imread('lenna256x256.bmp')); 
% M=50; 
% img2=Arnold(img,1,M,10,100); 
% img3=Arnold(img2,0,M,10,100); 
% imwrite(img3/255,'lenna256x2561.bmp'); 
% P=PSNR('lenna256x256.bmp','lenna256x2561.bmp'); 
% subplot(221); 
% imshow(img/255); 
% title('ԭʼͼ'); 
% subplot(223); 
% imshow(img2/255); 
% title('ͼ'); 
% subplot(224); 
% imshow(img3/255); 
% if P~=0 
%   title(sprintf('ظͼ(PSNR = %.2f dB)', P)); 
% else 
%   title(sprintf('ظͼ(ȫͬ)')); 
% end 
 
%ѡǷƫ 
switch nargin 
    case 3   %xy᲻ƫ 
        X=0; 
        Y=0; 
    case 4  %y᲻ƫ 
        Y=0; 
end 
%жͼСǷҪ 
[n,m]=size(img); 
if n~=m 
    error('Ƿʧ'); 
    return; 
end 
N=n; 
clear n m; 
 
%һԭ 
im=zeros(N,N); 
 for i=1:N 
  for j=1:N 
   x=i+X; 
   y=j+Y; 
   for k=1:M 
                temp1=x; 
    x=mod((x+y+X),N); 
    y=mod((temp1+2*y+X+Y),N);  
            end  %end for k=1:M 
   if x==0 
                x=N; 
            end 
   if y==0 
                y=N; 
            end 
            switch IP 
                case 1 
        im(x,y)=img(i,j); 
                case 0 
                 im(i,j)=img(x,y); 
            end  %end switch IP 
        end  %end for j=1:N 
    end  %end for i=1:N