找回密码
 注册
关于网站域名变更的通知
查看: 592|回复: 2
打印 上一主题 下一主题

基于matlab GUI DWT+DCT+PBFO改进图像水印隐藏提取

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2021-4-25 18:31 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x
( B( U0 q  N) y
一、引言) k% V* q, D* ^4 a: m3 C
该篇包括三部分,1)引言、2)图像变化技术简介和代码实现 、3)基于图像变换技术的数字水印技术及代码实现。
- ^6 D! e3 i# I/ |$ \) D  i数字水印是一种有效的数字产品版权保护和数据安全维护技术, 是信息隐藏领域的一个重要分支, 也是密码学的一种有益的补充技术。近年来它引起了人们的广泛关注。图像隐形水印是其中最主要的研究方向, 按照嵌入位置可分为空间域方法和变换域( DCT, DFT 和DWT 等) 方法。为了使水印信息有更好的鲁棒性(抵抗攻击的能力)众多学者采用变换域中的嵌入方法,前面我有两篇博客涉及到了有关DCT的数字水印方法和算法,接下来将分别介绍基于DCT、DFT、DWT三种基础图像变换技术的数字水印方法及代码实现。$ E- O" q( n1 C; V- y
9 a# y" s/ V1 _; u  @

/ b0 g6 T* X( G6 R: X; O  \- T二、DFT、DCT、DWT图像变换技术
) A2 w, ?: S$ j( {8 y
5 [, H3 o& ]& ?: T7 X图像变换技术是为了能让图像用正交函数或正交矩阵表示而对原图像所作的变换,该变换是二维线性可逆的。一般称原始图像为空间域图像,称变换后的图像为转换域图像(也称为频率域),转换域图像可反变换为空间域图像。经过图像变换后,一方面能够更有效地反映图像自身的特征,另一方面也可使能量集中在少量数据上,更有利于图像的存储、传输及处理。从数学角度来说,图像变换是把图像中的像素表达成“另外一种形式”满足实际需求,大多数情况下需要对变换处理后的图.像进行逆变换,从而获取处理以后的图像。这种变换同样可以应用于其他有关物理或数学的各种问题中,并可以采用其他形式的变量。在数字水印领域中,常用的基础图像变换技术有傅里叶变换(DFT)、离散余弦变换(DCT)、小波变换(DWT)。
. G( F  I4 g; r  ^/ z7 {2.1 图像傅里叶变换(DFT)
' ^( T2 }) p  B傅里叶变换是以时间为自变量的“信号”与频域为自变量的“频普”函数之间的某种变换关系。从纯粹的数学意义上看,傅立叶变换是将一个图像函数转换为一系列周期函数来处理的;从物理效果看,傅立叶变换是将图像从空间域转换到频率域,其逆变换是将图像从频率域转换到空间域。实际上对图像进行二维傅立叶变换得到频谱图,就是图像梯度的分布图,傅立叶频谱图上看到的明暗不一的亮点,实际上图像上某–点与邻域点差异的强弱,即梯度的大小,也即该点的频率大小。如果频谱图中暗的点数更多,那么实际图像是比较柔和的:反之,如果频谱图中亮的点数多,那么实际图像一定是尖锐的,边界分明且边界两边像素差异较大。4 h1 s# K1 g# G3 K
傅里叶变换包括一维连续傅里叶变换、二维连续傅里叶变换、一维离散傅里叶变换、二维离散傅里叶变换。在图像处理领域中常用二维离散傅里叶变换。其定义如下式(1):
4 ?9 Y. k! e) ~
$ o2 i9 ], u* Q " l# J( E% G0 J, f6 p
" u0 f7 W  g8 V2 U) \9 P: E
% X3 ~6 d- y+ e/ ~% O
二、源代码
, o! x: P; w3 I+ s+ f& t0 h
. V* E1 g' w# l5 J4 ?
  •   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('平移后的频谱');

  • 5 |- }* i9 `" J  c% r5 A
2 e& [8 E3 \0 W& x- \9 V" b. B
      
7 `$ p5 z* G% s' I9 ^0 u# g3 O: c  k/ t' B

7 s1 G2 P# X- i$ V% H5 O1 s8 |! Y其运行结果如下图:% s# T8 \: v9 ?, b
9 D; W5 w: l) s+ `

: j) U8 T% \! R9 D" c& l7 B. G
图1 图像傅里叶变换例
9 ]' r, c! }# ?3 K! E  E+ N4 Q; X$ e/ \! o. m: u
   2.2 离散余弦变换(DCT)
" t* _+ l" V: X7 `0 p# m# z8 D* o5 ~+ _5 |) I
   离散余弦变换(DCT)是一组不同频率和幅值的余弦函数和来近似一副图像,实际上是傅里叶变换的实数部分。由于离散余弦变量对于一副图像,其大部分可视化信息都集中在少数的变换系数上。因此,离散余弦变量是数据压缩常用的一个变换编码方法,它能将高相关数据能量集中,使得它非常适用于图像压缩,例如国际压缩标准的JPEG格式中就采用了离散余弦变换。, e- Y! D+ W  Q1 B2 I0 ?8 O+ \

! J' o, |! `6 T2 `" n   在傅立叶变换过程中,如果被展开的函数是实偶函数,那么其傅立叶变换中只包含余弦项,基于傅立叶变换的这一特点,人们提出了离散余弦变换。DCT变换先将图像函数变换成偶函数形式,再对其进行二维离散傅立叶变换,因此DCT变换可以看成是一种简化的傅立叶变换。离散余弦变换叶分为一维离散余弦变换和二维离散余弦变换,在图像处理中用到二维变化,所以介绍下其二维定义,其他定义可查阅《数字图像处理》——冈萨雷斯。其二维离散余弦变换定义如下式:
0 ]8 e  G& y/ T; J: [4 {  
9 _" x2 x) D  k! k( R: w  u6 M3 T: E% Z3 }: m0 t

/ L& e( |8 H& r8 C) I; L$ I+ t* O3 _; ]  c
  • 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('离散余弦变换系数图像');

  • # x1 o5 b6 ~3 z1 S3 w) ~% k+ L

  J9 p: D3 t- S; e
: y2 a& s/ P: V* ]
0 d6 ~9 U/ e0 c# T" X* v  v0 X( D! A: \$ s
其运行结果如下图2:0 u) q) G' W0 c' h! N2 X' m* n
9 Z6 ^0 J. x( ?$ L6 l; C  ]8 k

) g/ S3 _- v9 f5 q0 H1 y' Y; P1 H0 m

. f1 {" ~" `& \/ N; v/ j- E8 X图2 离散余弦变换例2 G5 F- B) T3 M% ~/ _! Z4 T

: c# h6 j% e  D" o   2.3 小波变换(DWT)9 f: S2 \2 v, L" G

3 B7 i( _. q4 _; H  小波变化是对傅里叶变换和短时傅里叶变换的一个突破,其改变就在于,将无限长的三角函数基换成了有限长的会衰减的小波。小波变化的理论较多,更多内容可查阅《数字图像处理》——冈萨雷斯相关章节内容,以下从一个叫简单的角度来解释小波变换。
1 |) {5 l. u: q8 G* b; E
6 a0 N+ ~9 i+ L+ y* T: S. j2 X: {  g8 r1 E

" Y3 s9 @5 Z  }3 o1 _5 b+ f. W! D* n' f. y, z  ~
3 R+ W1 @1 ^  A4 v
% S: s6 U  V( h" b% B+ c

9 O6 P1 H; v. H" ?% `0 W+ D表1 小波变换母小波
( V$ s0 X& u& _2 a7 I! x
% i  k7 `, }) l* z. l+ Y0 c  B1 [; P% |0 {& r9 Q
  • 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)
    % g' D2 k: `# {* ]5 n
               
7 o( I6 P# U5 o) f6 ~& N' f$ k
% d! Q' `/ w2 o5 i$ z( _  N2 H3 z' |8 F* g5 s' j/ D: H* t
; m5 ]0 \; {" X$ O
  • TA的每日心情

    2019-11-29 15:37
  • 签到天数: 1 天

    [LV.1]初来乍到

    2#
    发表于 2021-4-25 18:36 | 只看该作者
    基于matlab GUI DWT+DCT+PBFO改进图像水印隐藏提取

    该用户从未签到

    3#
    发表于 2021-4-26 18:50 | 只看该作者
    基于matlab GUI DWT+DCT+PBFO改进图像水印隐藏提取
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    关闭

    推荐内容上一条 /1 下一条

    EDA365公众号

    关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

    GMT+8, 2025-7-20 05:01 , Processed in 0.125000 second(s), 26 queries , Gzip On.

    深圳市墨知创新科技有限公司

    地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

    快速回复 返回顶部 返回列表