数字水印学习教程
本书介绍了数字水印的相关知识点及其 Matlab 实现,适合自学。希
望能对大家的学习有所帮助。如果问题请联系,lilizong@gmail.com
李立宗
1
目 录
1 程序界面..............................................................................................................................................5
1.1 程序代码......................................................................................................................................5
1.2 运行结果及说明........................................................................................................................18
2 空域操作............................................................................................................................................19
2.1 分层显示 .....................................................................................................................................19
2.1.1 程序代码..............................................................................................................................19
2.1.2 运行结果及说明..................................................................................................................20
2.2. 位值设置 ....................................................................................................................................22
2.2.1 代码实现..............................................................................................................................22
2.2.2 运行结果及说明..................................................................................................................25
2.3. 二值化 ........................................................................................................................................26
2.3.1 代码实现..............................................................................................................................26
2.3.2 运行结果及说明..................................................................................................................27
2.4. SOBEL边缘检测...........................................................................................................................28
2.4.1 代码实现..............................................................................................................................28
2.4.2 运行结果及说明..................................................................................................................29
2.5. 分块求均值 ................................................................................................................................30
2.5.1 代码实现..............................................................................................................................30
2.5.2 运行结果及说明..................................................................................................................32
2.6. 元胞自动机 ................................................................................................................................33
2.6.1 代码实现..............................................................................................................................33
2.6.2 运行结果及说明..................................................................................................................36
2.7. LSB算法演示..............................................................................................................................37
2.7.1 代码实现..............................................................................................................................37
2.7.2 运行结果及说明..................................................................................................................39
2.8. LSB嵌入水印..............................................................................................................................41
2.8.1 代码实现..............................................................................................................................41
2.8.2 运行结果及说明..................................................................................................................43
2.9. LSB提取水印..............................................................................................................................46
2.9.1 代码实现..............................................................................................................................46
2.9.2 运行结果及说明..................................................................................................................48
3 DWT 操作 .........................................................................................................................................50
3.1 1 层DWT....................................................................................................................................50
3.1.1 程序代码..............................................................................................................................50
3.1.2 运行结果及说明..................................................................................................................52
3.2 2 层DWT....................................................................................................................................55
3.2.1 程序代码..............................................................................................................................55
3.2.2 运行结果及说明..................................................................................................................57
3.3 3 层DWT....................................................................................................................................58
1
3.3.1 程序代码..............................................................................................................................58
3.3.2 运行结果及说明..................................................................................................................60
3.4 DWT水印演示(逼近子带)...................................................................................................61
3.4.1 程序代码..............................................................................................................................61
3.4.2 运行结果及说明..................................................................................................................64
3.5 DWT子带水印(对角线).......................................................................................................66
3.5.1 程序代码..............................................................................................................................66
3.5.2 运行结果及说明..................................................................................................................69
3.6 DWT嵌入水印(逼近子带)...................................................................................................71
3.6.1 程序代码..............................................................................................................................71
3.6.2 运行结果及说明..................................................................................................................74
3.7 DWT提取水印(逼近子带)...................................................................................................77
3.7.1 程序代码..............................................................................................................................77
3.7.2 运行结果及说明..................................................................................................................81
3.8 2 层DWT水印(逼近子带)....................................................................................................83
3.8.1 程序代码..............................................................................................................................83
3.8.2 运行结果及说明..................................................................................................................86
3.9 2 层DWT水印(对角线)........................................................................................................88
3.9.1 程序代码..............................................................................................................................88
3.9.2 运行结果及说明..................................................................................................................91
3.10 3 层DWT水印(逼近子带)..................................................................................................93
3.10.1 程序代码............................................................................................................................93
3.10.2 运行结果及说明................................................................................................................96
3.11 3 层DWT水印(对角线)......................................................................................................98
3.11.1 程序代码............................................................................................................................98
3.11.2 运行结果及说明..............................................................................................................101
4 提升小波操作..................................................................................................................................103
4.1 1 层LWT ..................................................................................................................................103
4.1.1 程序代码............................................................................................................................103
4.1.2 运行结果及说明................................................................................................................105
4.2 2 层LWT ..................................................................................................................................107
4.2.1 程序代码............................................................................................................................107
4.2.2 运行结果及说明................................................................................................................109
4.3 3 层LWT ..................................................................................................................................110
4.3.1 程序代码............................................................................................................................ 110
4.3.2 运行结果及说明................................................................................................................ 112
4.4 LWT水印演示(逼近子带)..................................................................................................113
4.4.1 程序代码............................................................................................................................ 113
4.4.2 运行结果及说明................................................................................................................ 116
4.5 LWT子带水印(对角线) .....................................................................................................118
4.5.1 程序代码............................................................................................................................ 118
4.5.2 运行结果及说明................................................................................................................121
4.6 LWT嵌入水印(逼近子带)..................................................................................................123
4.6.1 程序代码............................................................................................................................123
2
4.6.2 运行结果及说明................................................................................................................126
4.7 LWT提取水印(逼近子带)..................................................................................................129
4.7.1 程序代码............................................................................................................................129
4.7.2 运行结果及说明................................................................................................................133
4.8 2 层LWT水印(逼近子带)...................................................................................................135
4.8.1 程序代码............................................................................................................................135
4.8.2 运行结果及说明................................................................................................................138
4.9 2 层LWT水印(对角线) ......................................................................................................140
4.9.1 程序代码............................................................................................................................140
4.9.2 运行结果及说明................................................................................................................143
4.10 3 层LWT水印(逼近子带).................................................................................................145
4.10.1 程序代码..........................................................................................................................145
4.10.2 运行结果及说明..............................................................................................................148
4.11 3 层LWT水印(对角线).....................................................................................................150
4.11.1 程序代码..........................................................................................................................150
4.11.2 运行结果及说明..............................................................................................................153
5 混沌操作..........................................................................................................................................155
5.1 生成混沌图像..........................................................................................................................155
5.1.1 程序代码............................................................................................................................155
5.1.2 运行结果及说明................................................................................................................157
5.2 混沌加密水印图像..................................................................................................................159
5.2.1 程序代码............................................................................................................................159
5.2.2 运行结果及说明................................................................................................................161
5.3 混沌置乱演示..........................................................................................................................163
5.3.1 程序代码............................................................................................................................163
5.3.2 运行结果及说明................................................................................................................165
5.4 混沌加密图像(置乱)..........................................................................................................167
5.4.1 程序代码............................................................................................................................167
5.4.2 运行结果及说明................................................................................................................170
5.5 混沌解密图像(逆置乱)......................................................................................................172
5.5.1 程序代码............................................................................................................................172
5.5.2 运行结果及说明................................................................................................................174
6 攻击模拟..........................................................................................................................................176
6.1 JPEG压缩.................................................................................................................................176
6.1.1 程序代码............................................................................................................................176
6.1.2 运行结果及说明................................................................................................................177
6.2 椒盐攻击..................................................................................................................................180
6.2.1 程序代码............................................................................................................................180
6.2.2 运行结果及说明................................................................................................................181
6.3 高斯攻击..................................................................................................................................183
6.3.1 程序代码............................................................................................................................183
6.3.2 运行结果及说明................................................................................................................184
6.4 旋转..........................................................................................................................................186
3
6.4.1 程序代码............................................................................................................................186
6.4.2 运行结果及说明................................................................................................................188
6.5 裁剪..........................................................................................................................................190
6.5.1 程序代码............................................................................................................................190
6.5.2 运行结果及说明................................................................................................................193
6.6 抖动..........................................................................................................................................195
6.6.1 程序代码............................................................................................................................195
6.6.2 运行结果及说明................................................................................................................196
6.7 放大..........................................................................................................................................198
6.7.1 程序代码............................................................................................................................198
6.7.2 运行结果及说明................................................................................................................200
6.8 缩小..........................................................................................................................................202
6.8.1 程序代码............................................................................................................................202
6.8.2 运行结果及说明................................................................................................................204
6.9 滤波..........................................................................................................................................206
6.9.1 程序代码............................................................................................................................206
6.9.2 运行结果及说明................................................................................................................209
7 帮助.................................................................................................................................................. 211
7.1 说明..........................................................................................................................................211
7.1.1 程序代码............................................................................................................................ 211
7.1.2 运行结果及说明................................................................................................................213
7.2 关于..........................................................................................................................................215
7.2.1 程序代码............................................................................................................................215
7.2.2 运行结果及说明................................................................................................................216
4
1 程序界面
1.1 程序代码
function varargout = my2(varargin)
% MY2 M-file for my2.fig
% MY2, by itself, creates a new MY2 or raises the existing
% singleton*.
%
% H = MY2 returns the handle to a new MY2 or the handle to
% the existing singleton*.
%
% MY2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MY2.M with the given input arguments.
%
% MY2('Property','Value',...) creates a new MY2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before my2_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to my2_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 my2
% Last Modified by GUIDE v2.5 23-May-2009 22:57:56
% imshow('a.bmp');
5
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @my2_OpeningFcn, ...
'gui_OutputFcn', @my2_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 my2 is made visible.
function my2_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 my2 (see VARARGIN)
% Choose default command line output for my2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
subplot(1,1,1),imshow('fengmian.bmp');
% UIWAIT makes my2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
6
% --- Outputs from this function are returned to the command line.
function varargout = my2_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;
% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_3_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function Untitled_4_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
7