【图像隐藏】基于 FFT实现数字水印嵌入含Matlab源码
作者:互联网
1 简介
基于 FFT实现数字水印嵌入
2 部分代码
%Watermarking based on FFT
clc
clear all
close 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);
end
Logo = 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!
3 仿真结果
4 参考文献
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。
标签:subplot,imshow,title,Image,FFT,源码,数字水印,Logo 来源: https://blog.csdn.net/qq_59747472/article/details/123419824