|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
/ v* o8 t/ }" F% B一、引言
2 _( h9 E2 d9 f( u! C4 w该篇包括三部分,1)引言、2)图像变化技术简介和代码实现 、3)基于图像变换技术的数字水印技术及代码实现。- k1 }5 W+ L; t% w
数字水印是一种有效的数字产品版权保护和数据安全维护技术, 是信息隐藏领域的一个重要分支, 也是密码学的一种有益的补充技术。近年来它引起了人们的广泛关注。图像隐形水印是其中最主要的研究方向, 按照嵌入位置可分为空间域方法和变换域( DCT, DFT 和DWT 等) 方法。为了使水印信息有更好的鲁棒性(抵抗攻击的能力)众多学者采用变换域中的嵌入方法,前面我有两篇博客涉及到了有关DCT的数字水印方法和算法,接下来将分别介绍基于DCT、DFT、DWT三种基础图像变换技术的数字水印方法及代码实现。
2 p8 {7 a& z4 ]: m/ |& e9 C& L) P M9 f
3 ?+ Z! C2 G0 k0 U# ?/ m
二、DFT、DCT、DWT图像变换技术6 l! ]2 i" q! l" i
9 b1 h7 C2 v( W& m: Z图像变换技术是为了能让图像用正交函数或正交矩阵表示而对原图像所作的变换,该变换是二维线性可逆的。一般称原始图像为空间域图像,称变换后的图像为转换域图像(也称为频率域),转换域图像可反变换为空间域图像。经过图像变换后,一方面能够更有效地反映图像自身的特征,另一方面也可使能量集中在少量数据上,更有利于图像的存储、传输及处理。从数学角度来说,图像变换是把图像中的像素表达成“另外一种形式”满足实际需求,大多数情况下需要对变换处理后的图.像进行逆变换,从而获取处理以后的图像。这种变换同样可以应用于其他有关物理或数学的各种问题中,并可以采用其他形式的变量。在数字水印领域中,常用的基础图像变换技术有傅里叶变换(DFT)、离散余弦变换(DCT)、小波变换(DWT)。
" ^! v3 l0 y v: u1 [5 H+ ]% l2.1 图像傅里叶变换(DFT)
8 P- ]0 k! f4 a% F8 ~傅里叶变换是以时间为自变量的“信号”与频域为自变量的“频普”函数之间的某种变换关系。从纯粹的数学意义上看,傅立叶变换是将一个图像函数转换为一系列周期函数来处理的;从物理效果看,傅立叶变换是将图像从空间域转换到频率域,其逆变换是将图像从频率域转换到空间域。实际上对图像进行二维傅立叶变换得到频谱图,就是图像梯度的分布图,傅立叶频谱图上看到的明暗不一的亮点,实际上图像上某–点与邻域点差异的强弱,即梯度的大小,也即该点的频率大小。如果频谱图中暗的点数更多,那么实际图像是比较柔和的:反之,如果频谱图中亮的点数多,那么实际图像一定是尖锐的,边界分明且边界两边像素差异较大。
# ~7 C) b6 r( y$ u) i* A7 d傅里叶变换包括一维连续傅里叶变换、二维连续傅里叶变换、一维离散傅里叶变换、二维离散傅里叶变换。在图像处理领域中常用二维离散傅里叶变换。其定义如下式(1):
2 u+ {" U% [) Z3 k! Q8 C1 o; x6 u' D/ E7 j
% M! `0 V. I3 d
' E+ K+ h% d6 K8 c% Z5 N- s7 f0 Y
' y6 ~9 `( `2 d* R0 O: j7 a二、源代码
0 g7 f; j, G% \% b& l( t: M: w7 t* N3 k$ i2 g
- 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('原始图像');
- subplot(2,2,2);
- imshow(J); title('灰度图像');
- subplot(2,2,3);
- imshow(uint8(L_1)); title('灰度图像傅里叶频谱');
- subplot(2,2,4);
- imshow(uint8(L_2)); title('平移后的频谱');
$ d3 \7 l7 F3 k4 i6 m4 W # } S, i0 n z2 s/ J
9 z/ S) V, L7 s* V& W* Y3 I; ~* I2 M. m5 h8 H0 T y
1 M0 Q+ `0 Q! F% N3 q. W+ q其运行结果如下图:0 g5 \7 @, T1 J% S' f- {0 M
9 O1 W6 p; k: L7 H' D
+ {( h/ d3 G$ V" P6 }# s, x
6 \) h$ u8 O0 i# z8 y0 f+ I图1 图像傅里叶变换例9 U) t% P2 T, x6 r' g6 ^5 b
% R9 }4 ~2 P; q" b! a
2.2 离散余弦变换(DCT)! x2 \$ E! k9 ~& M% u0 B& k) ?* s8 k
1 Q1 K% j+ E8 v) o) I 离散余弦变换(DCT)是一组不同频率和幅值的余弦函数和来近似一副图像,实际上是傅里叶变换的实数部分。由于离散余弦变量对于一副图像,其大部分可视化信息都集中在少数的变换系数上。因此,离散余弦变量是数据压缩常用的一个变换编码方法,它能将高相关数据能量集中,使得它非常适用于图像压缩,例如国际压缩标准的JPEG格式中就采用了离散余弦变换。
. D6 i/ v* R% ^1 n1 J8 Y
1 m+ u0 l8 |; G! y) \% i* h 在傅立叶变换过程中,如果被展开的函数是实偶函数,那么其傅立叶变换中只包含余弦项,基于傅立叶变换的这一特点,人们提出了离散余弦变换。DCT变换先将图像函数变换成偶函数形式,再对其进行二维离散傅立叶变换,因此DCT变换可以看成是一种简化的傅立叶变换。离散余弦变换叶分为一维离散余弦变换和二维离散余弦变换,在图像处理中用到二维变化,所以介绍下其二维定义,其他定义可查阅《数字图像处理》——冈萨雷斯。其二维离散余弦变换定义如下式:
; ?% G' N1 o5 ^5 E
# l! n5 Q, P, F& Y. m9 d3 \: t
, c4 f1 v. z: [+ M4 N, ]5 E- A& X% j! t0 j
* g" D6 w% O% B# W& B- close all;
- clear all;
- clc;
- I = imread ('boats.bmp');
- J = dct2(I);
- figure('Name','离散余弦变换');
- subplot(1,2,1);
- imshow(I); title('原始图像');
- subplot(1,2,2);
- imshow(log(abs(J))); title('离散余弦变换系数图像');
1 ^2 l, c t: Y N" {
8 n1 m- d3 p- w8 ~3 o) b& ?% C# q6 D4 n5 l* H
7 T. Z5 t4 e3 p6 m! F9 W( ^9 l4 a
" W8 y4 y6 q2 ]
其运行结果如下图2:8 S6 K a! f: J4 E8 ]- A
; w7 n" e, {& O: P" ]# A
& k* u0 A+ _' o' S: I( l5 q( u' [+ n
5 ?; l) c9 v. |) x o( k/ o" e2 j, w8 N
图2 离散余弦变换例: I& H: A" v9 W- B1 p1 _8 S M
/ I5 Z/ a3 a/ x/ C 2.3 小波变换(DWT)
6 B8 r) M& D8 S E) t) N8 }" a" G I
小波变化是对傅里叶变换和短时傅里叶变换的一个突破,其改变就在于,将无限长的三角函数基换成了有限长的会衰减的小波。小波变化的理论较多,更多内容可查阅《数字图像处理》——冈萨雷斯相关章节内容,以下从一个叫简单的角度来解释小波变换。% ^" g' _8 i: x! q/ A5 o. k
. t n, b; u. w! x3 ?, L7 f9 f( A7 p O3 `
- S* O" m" a1 y( F, u' v" `
% J" ?9 r7 Q- t1 [( N
6 m) r# B3 q3 T4 K# ]3 Y
# i9 W; c5 I; \" \4 W
! ]0 Z4 p. ^$ S# k2 t0 W7 r. P表1 小波变换母小波1 M' Y; k' e- c* @
- _# L1 Z% f. M* \! n: h
' R3 z8 W( ~! {- 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 a new 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)
. M% Q, t9 Z# ^8 w: V7 }: C1 T
2 |; v1 E1 Y; w$ [; h. Z6 ]4 @, D
% M q E: N7 I7 r1 _3 m# i4 m+ m3 S. S& F- e
( u$ k( K6 d! _+ t% M
|
|