One, the introduction
This paper includes three parts: 1) introduction, 2) introduction of image change technology and code implementation, 3) digital watermarking technology and code implementation based on image transformation technology. Digital watermarking is an effective technology for copyright protection and data security maintenance of digital products, an important branch of information hiding field, and a beneficial complementary technology of cryptography. It has attracted wide attention in recent years. Invisible image watermarking is the most important research direction, which can be divided into spatial domain method and transform domain method (DCT, DFT and DWT) according to the embedding position. In order to make the watermark has better robustness (ability to resist attacks) embedding method of numerous scholars using the transform domain, I have two in front of the post involves the DCT watermarking method and algorithm, the following will introduce respectively based on DCT, DFT and DWT three basic transformation technology of digital image watermarking method and code implementation.
Second, DFT, DCT, DWT image transformation technology
Image transformation technology is in order to make the image with orthogonal functions or orthogonal matrix representation of the original image transformation, the transformation is two-dimensional linear reversible. The original image is generally called the spatial domain image, and the transformed image is called the transformation domain image (also known as the frequency domain). The transformation domain image can be inversely transformed into the spatial domain image. After image transformation, on the one hand, it can reflect the characteristics of the image itself more effectively, on the other hand, it can also make the energy focus on a small amount of data, which is more conducive to image storage, transmission and processing. From a mathematical point of view, image transformation is to express the pixels in the image into “another form” to meet the actual needs. In most cases, the image after transformation processing is needed. The image is inversely transformed to obtain the processed image. This transformation can also be applied to other kinds of problems related to physics or mathematics and can take other forms of variables. In the field of digital watermarking, Fourier transform (DFT), discrete cosine transform (DCT) and wavelet transform (DWT) are commonly used as basic image transformation techniques.
2.1 Fourier Transform of Images (DFT)
The Fourier transform is a kind of transformation relationship between the time independent variable “signal” and the frequency domain independent variable “frequency general” function. In a purely mathematical sense, the Fourier transform is processed by converting an image function into a series of periodic functions. In terms of physical effects, the Fourier transform transforms the image from the spatial domain to the frequency domain, while the inverse transform transforms the image from the frequency domain to the spatial domain. In fact, the two-dimensional Fourier transform of the image to get the spectral map, is the distribution of the image gradient, the Fourier spectrum map to see the light and dark spots, in fact, the image of a point and the strength of the neighborhood point difference, that is, the size of the gradient, that is, the frequency of the point. If there are more dark points in the spectrum, then the actual image is soft; conversely, if there are more bright points in the spectrum, then the actual image must be sharp, with clear boundaries and large differences in pixels on both sides of the boundary.
The Fourier transform includes the one-dimensional continuous Fourier transform, the two-dimensional continuous Fourier transform, the one-dimensional discrete Fourier transform, and the two-dimensional discrete Fourier transform. Two-dimensional discrete Fourier transform is commonly used in the field of image processing. Its definition is as follows (1) :
Ii. Source code
close all;
clear all;
clc;
I = imread('pepper.bmp');
J = rgb2gray(I);
K_1 = fft2(J);
L_1 = abs(K_1/256);
K_2 = fftshift(K_1);
L_2 = abs(K_2/256);
figure;
subplot(2.2.1);
imshow(I); title('Original image');
subplot(2.2.2);
imshow(J); title('Grayscale image');
subplot(2.2.3);
imshow(uint8(L_1)); title('Fourier spectrum of grayscale images');
subplot(2.2.4);
imshow(uint8(L_2)); title('Shifted spectrum');
Copy the code
Its running results are shown as follows:
FIG. 1 Example of Fourier transform of image
The discrete cosine Transform (DCT) is a sum of cosine functions of different frequencies and amplitudes to approximate an image, which is actually the real part of the Fourier transform. Because of the discrete cosine variable for an image, most of its visual information is concentrated on a few transformation coefficients. Therefore, discrete cosine variable is a commonly used transformation coding method for data compression. It can concentrate the energy of highly relevant data, making it very suitable for image compression. For example, the international compression standard JPEG format uses discrete cosine transform. In the Process of Fourier transform, if the expanded function is even function, then the Fourier transform only contains cosine term. Based on this characteristic of Fourier transform, people put forward discrete cosine transform. DCT transform first transforms the image function into even function form, and then performs two-dimensional discrete Fourier transform on it. Therefore, DCT transform can be regarded as a simplified Fourier transform. Discrete cosine transform leaves are divided into one-dimensional discrete cosine transform and two-dimensional discrete cosine transform. Two-dimensional changes are used in image processing, so the two-dimensional definition is introduced. For other definitions, please refer to Digital Image Processing -- Gonzales. Its two-dimensional discrete cosine transform is defined as follows: [insert picture description here] (HTTP: / / https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/4ac221c9f1ca4466af6400b97e92ed32~tplv-k3u1fbpfcp-zoom-1.im age)Copy the code
close all;
clear all;
clc;
I = imread ('boats.bmp');
J = dct2(I);
figure('Name'.Discrete cosine transform);
subplot(1.2.1);
imshow(I); title('Original image');
subplot(1.2.2);
imshow(log(abs(J))); title('DCT coefficient image');
Copy the code
Its running results are shown in Figure 2:
FIG. 2 Example of discrete cosine transform
Wavelet transform is a breakthrough of Fourier transform and short-time Fourier transform, and its change lies in that the infinite length of trigonometric function basis is replaced by the finite length of the decaying wavelet. Wavelet transform theory is more, more content can refer to "digital Image Processing" - Gonzalez related chapter content, the following from a simple point of view to explain wavelet transform. ! [insert picture description here] (HTTP: / / https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/938f3b2fe6824928b70b229b0e8b2bd1~tplv-k3u1fbpfcp-zoom-1.im age)Copy the code
Table 1 Wavelet transform mother wavelet
function varargout = manit1(varargin)
% MANIT1 M-file for manit1.fig
% MANIT1, by itself, creates a new MANIT1 or raises the existing
% singleton*.
%
% H = MANIT1 returns the handle to a new MANIT1 or the handle to
% the existing singleton*.
%
% MANIT1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MANIT1.M with the given input arguments.
%
% MANIT1('Property'.'Value',...). creates anew MANIT1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before manit1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to manit1_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help manit1
% Last Modified by GUIDE v2. 5 14-Jun- 2015. 10:32:30
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @manit1_OpeningFcn, ...
'gui_OutputFcn', @manit1_OutputFcn, ...
'gui_LayoutFcn', [],...'gui_Callback'[]);if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before manit1 is made visible.
function manit1_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to manit1 (see VARARGIN)
% Choose default command line output for manit1
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes manit1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = manit1_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in browsecoverimg.
function browsecoverimg_Callback(hObject, eventdata, handles)
% hObject handle to browsecoverimg (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.jpg';'*.bmp';'*.gif';'*. *'}, 'Pick an Image File');
S = imread([pathname,filename]);
S=imresize(S,[512.512]);
axes(handles.axes1)
imshow(S)
title('Cover Image')
set(handles.text3,'string',filename)
handles.S=S;
guidata(hObject,handles)
% --- Executes on button press in browsemsg.
function browsemsg_Callback(hObject, eventdata, handles)
% hObject handle to browsemsg (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.bmp';'*.jpg';'*.gif';'*. *'}, 'Pick an Image File');
msg = imread([pathname,filename]);
axes(handles.axes2)
imshow(msg)
title('Input Message')
set(handles.text4,'string',filename)
handles.msg=msg;
guidata(hObject,handles)
% --- Executes on button press in DWT.
function DWT_Callback(hObject, eventdata, handles)
% hObject handle to DWT (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
message=handles.msg;
cover_object=handles.S;
k=10;
[watermrkd_img,PSNR,IF,NCC,recmessage]=dwt(cover_object,message,k);
axes(handles.axes3)
imshow(watermrkd_img)
title('Watermarked Image')
axes(handles.axes4)
imshow(recmessage)
title('Recovered Message')
a=[PSNR,NCC,IF]';
t=handles.uitable1;
set(t,'Data',a)
handles.a=a;
guidata(hObject,handles)
% --- Executes on button press in DWTDCT.
function DWTDCT_Callback(hObject, eventdata, handles)
% hObject handle to DWTDCT (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a=handles.a;
message=handles.msg;
cover_object=handles.S;
k=10;
[watermrkd_img,recmessage,PSNR,IF,NCC1] = dwtdct(cover_object,message,k);
axes(handles.axes3)
imshow(watermrkd_img)
title('DWT+DCT Watermarked Image')
axes(handles.axes4)
imshow(recmessage)
title('DWT+DCT Recovered Message')
b=[PSNR,NCC1,IF]';
t=handles.uitable1;
set(t,'Data',[a b])
handles.b=b;
guidata(hObject,handles)
% --- Executes on button press in DWTDCTBFO.
function DWTDCTBFO_Callback(hObject, eventdata, handles)
% hObject handle to DWTDCTBFO (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a=handles.a;
b=handles.b;
message=handles.msg;
cover_object=handles.S;
[watermrkd_img,recmessage,PSNR,IF,NCC,pbest] = BG(cover_object,message);
axes(handles.axes3)
imshow(watermrkd_img)
title('DWT+DCT+BFO Watermarked Image')
axes(handles.axes4)
imshow(recmessage)
title('DWT+DCT+BFO Recovered Message')
c=[PSNR,NCC,IF]';
t=handles.uitable1;
set(t,'Data',[a b c])
handles.c=c;
guidata(hObject,handles)
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a=handles.a;
b=handles.b;
c=handles.c;
d=handles.d;
PSNR=[a(1),b(1),c(1),d(1)]; NCC=[a(2),b(2),c(2),d(2)];
IF=[a(3),b(3),c(3),d(3)];
figure
bar(PSNR)
set(gca,'XTickLabel'.' ');
ylabel('PSNR')
text(1.0.'DWT'.'Rotation'.260.'Fontsize'.8);
text(2.0.'DWT+DCT'.'Rotation'.260.'Fontsize'.8);
text(3.0.'DWT+DCT+BFO'.'Rotation'.260.'Fontsize'.8);
text(4.0.'DWT+DCT+PBFO'.'Rotation'.260.'Fontsize'.8);
[t]=get(gca,'position');
set(gca,'position',[t(1) 0.31 t(3) 0.65])
title('Bar Graph Comparison of PSNR') % % % %figure
bar(NCC)
set(gca,'XTickLabel'.' ');
ylabel('NCC')
text(1.0.'DWT'.'Rotation'.260.'Fontsize'.8);
text(2.0.'DWT+DCT'.'Rotation'.260.'Fontsize'.8);
text(3.0.'DWT+DCT+BFO'.'Rotation'.260.'Fontsize'.8);
text(4.0.'DWT+DCT+PBFO'.'Rotation'.260.'Fontsize'.8);
[t]=get(gca,'position');
set(gca,'position',[t(1) 0.31 t(3) 0.65])
title('Bar Graph Comparison of NCC')
% --- Executes on button press in DWTDCTPBFO.
function DWTDCTPBFO_Callback(hObject, eventdata, handles)
% hObject handle to DWTDCTPBFO (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a=handles.a;
b=handles.b;
c=handles.c;
message=handles.msg;
cover_object=handles.S;
[watermrkd_img,recmessage,PSNR,IF,NCC,pbest] =BG_PSO(cover_object,message);
axes(handles.axes3)
imshow(watermrkd_img)
title('DWT+DCT+PBFO Watermarked Image')
axes(handles.axes4)
imshow(recmessage)
title('DWT+DCT+PBFO Recovered Message')
d=[PSNR,NCC,IF]';
t=handles.uitable1;
set(t,'Data',[a b c d])
handles.d=d;
guidata(hObject,handles)
Copy the code
Third, note
Version: 2014 a