基于 FFT实现数字水印嵌入
%Watermarking based on FFTclcclear allclose all%Reading Original Image[FileName,FilePath] = uigetfile('*.*');Image = imread([FilePath,FileName]);if size(image,3) == 1 Image = rgb2gray (Image);end[ImageRows,ImageColoumns] = size(Image);%Reading Logo[FileName,FilePath] = uigetfile('*.*');Logo = imread([FilePath,FileName]);if size(Logo,3) == 1 Logo = rgb2gray(Logo);endLogo = im2bw(Logo,0.7);[LogoRows,LogoColoumns] = size(Logo);figure, subplot(2,3,1),imshow(Image);title('Original Image') subplot(2,3,4),imshow(Logo);title('Logo')%Water Mark Logo, lines 17 & 18 also can be used for Logo extraction.ImageFFT = fft2(Image);ImageFFTshift = fftshift(ImageFFT);ImageFFTshift2 = ImageFFTshift;%Is used for inserting the Logo far from center of FFT.%Inserting the Logo to center of the FFT shifted Image. ImageFFTshift(ImageRows / 2:(ImageRows / 2+ LogoRows - 1), ...ImageColoumns / 2 :(ImageColoumns / 2 + LogoColoumns - 1)) = Logo;% Reversing the FFT to obtain Image in spatial domain.WaterMArkedImage = ifftshift(ImageFFTshift);WaterMArkedImage = ifft2(WaterMArkedImage);subplot(2,3,2),imshow(uint8(WaterMArkedImage))title('Watermarked Image')subplot(2,3,5),imshow(ImageFFTshift);title('Embeded Logo in FFT2')%Inserting the Logo outside the center of the FFT shifted Image. ImageFFTshift2(10:(10 + LogoRows - 1),5 : 5 + LogoColoumns - 1)= Logo;WaterMArkedImage2 = ifftshift(ImageFFTshift2);WaterMArkedImage2 = ifft2(WaterMArkedImage2);subplot(2,3,3),imshow(uint8(WaterMArkedImage2));title('Watermarked Image')subplot(2,3,6),imshow(ImageFFTshift2);title('Embeded Logo in FFT2')%When logo is far from center Image quality dose not change!
部分理论引用网络文献,若有侵权联系博主删除。