图像隐写基于LSB+DCT实现数字水印嵌入提取带攻击测试matlab源码含GUI
Posted Matlab咨询QQ1575304183
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图像隐写基于LSB+DCT实现数字水印嵌入提取带攻击测试matlab源码含GUI相关的知识,希望对你有一定的参考价值。
一、简介
1 LSB算法简介
LSB全称为 Least Significant Bit(最低有效位),是一种简单而有效的数据隐藏技术。LSB隐写的基本方法是用欲嵌入的秘密信息取代载体图像的最低比特位,原来的图像的高位平面与代表秘密信息的最低平面组成含隐蔽信息的新图像。
灰度化的图像为单通道格式存储像素,每个像素值在0~255内,而像素的位平面则是对应二进制的像素的各个位。以上图为例,某个像素的值为78,其二进制01001110,从左到右位权依次降低,最左边为最高有效位(MSB,其位权为 2 7 2^72
7
),最右边位最低有效位(LSB,位权为2 0 2^02
0
)。把每个像素的相同位抽取出来组成一个新的平面,就是所谓的图的位平面。而LSB隐写算法,如其名字,是在LSB也就是最低位平面进行信息嵌入/隐藏。
需要注意的一点是,LSB嵌入的时候,载体图像格式应该为灰度图格式
以著名的Lena图为例,一下是灰度图Lena原图:
下面是其各个位平面图,从左到右、从上到下位平面依次降低:
可以看到,位平面越高包含的原图像信息越多,对图像的灰度值贡献越大,并且相邻比特的相关性也越强,反之则相反。LSB最低位平面基本上不包含图像信息了,类似随机的噪点/噪声,因此,可以在此处填入水印/秘密信息。
嵌入示意图如下:
选取不同位平面嵌入时,LSB算法的保真度:
2 算法原理
通俗来讲我们看到的图片都是由一个个小的像素点来构成的,所有像素点摆在一起,构成一个大方块,这个大方块就是我们所见的图像。灰度图像(也就是我们平时所说的黑白图像)是由一层像素点组成的,而彩色图像是由三层这样的灰度图像组成的。这里拿灰度图像举例,我们之所以能在图像上看到黑色和白色,是因为每个像素点的像素值不同。0表示纯黑,255表示纯白,灰色就是由这两个数字之间的值构成。越靠近0越黑,越靠近255越白。那为什么是0和255呢?因为计算机是二进制,它会用8个比特来表示一个像素点(也可以用更多的比特,这样图像的颜色分级就越多,同时图像也会占用更大的空间,但是普通人的眼睛并不能辨认这么多的颜色,除非你异于常人),所以最大值是255,最小是0。lsb就是基于2进制这一特点来隐藏信息的,因为人眼并不是很精密的颜色或亮度的感知器,所以把像素灰度上下微调1是不会被人眼察觉的,也就是修改8位二进制码中最小的一位。当我们把图片每个像素的最后一位按照我们的想法改变,使他表现为我们想要的信息,但用户却不能看出,也不会影响图片的内容。这就是lsb数字水印。
3 LSB算法的基本特点:
LSB是一种大容量的数据隐藏算法
LSB的鲁棒性相对较差(当stego图像遇到信号处理,比如:加噪声,有损压缩等,在提取嵌入信息时会丢失)
4 常见LSB算法的嵌入方法:
秘密信息在最低位平面连续嵌入至结束,余下部分不作任何处理(典型软件MandelSteg)
秘密信息在最低位平面连续嵌入至结束,余下部分随机化处理(也称沙化处理,典型软件PGMStealth)
秘密信息在最低位平面和次低位平面连续嵌入,并且是同时嵌入最低位平面和次低位平面
秘密信息在最低位平面嵌入,等最低位平面嵌入完全嵌入之后,再嵌入次低位平面
秘密信息在最低位平面随机嵌入
以上五种方式,当嵌入容量不同时,鲁棒性不同
二、源代码
function varargout = watermaked(varargin)
% WATERMAKED M-file for watermaked.fig
% WATERMAKED, by itself, creates a new WATERMAKED or raises the existing
% singleton*.
%
% H = WATERMAKED returns the handle to a new WATERMAKED or the handle to
% the existing singleton*.
%
% WATERMAKED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in WATERMAKED.M with the given input arguments.
%
% WATERMAKED('Property','Value',...) creates a new WATERMAKED or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before watermaked_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to watermaked_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 watermaked
% Last Modified by GUIDE v2.5 26-May-2008 14:22:42
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @watermaked_OpeningFcn, ...
'gui_OutputFcn', @watermaked_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 watermaked is made visible.
function watermaked_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 watermaked (see VARARGIN)
% Choose default command line output for watermaked
handles.output = hObject;
handles.contain=imread('nvlang512x512.jpg'); % 读入载体图
handles.name=imread('name32x32.bmp'); % 读入水印
handles.sel=0; % 不加攻击
handles.jpeg=0;
handles.gau=0;
handles.salt=0;
handles.ang=0;
handles.filt=0; % 不滤波
set(handles.edit3,'string',handles.jpeg); % 文本框设置为0
set(handles.edit2,'string',handles.jpeg);
set(handles.edit1,'string',handles.jpeg);
set(handles.edit7,'string',handles.ang);
guidata(hObject, handles);
guidata(hObject, handles);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes watermaked wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = watermaked_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
contain_ind=rgb2gray(handles.contain); % 灰度图象 可以接受
figure,imshow(uint8(contain_ind)); title('原始图象');
guidata(hObject, handles);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
figure,imshow(handles.name);title('水印');
guidata(hObject, handles);
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[handles.contain_lsb,handles.bit]=LSB;
figure,imshow(handles.contain_lsb);
handles.pnsr=PSNR(handles.contain,handles.contain_lsb);
title_string=strcat('含水印的图象(时域) PNSR:',num2str(handles.pnsr));
title(title_string);
guidata(hObject, handles);
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.watermarked_lsb=LSBextract(handles.contain,handles.contain_lsb,handles.name,handles.bit,handles.sel,handles.gau,handles.salt,handles.jpeg,handles.filt,handles.ang);
figure,imshow(uint8(handles.watermarked_lsb));title('提取的水印(时域)');
guidata(hObject, handles);
% --- Executes on button press in pushbutton20.
function pushbutton20_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton20 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
delete(get(0,'children'));
clear all;
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[handles.contain_marker_dwt,handles.SORT_IND]=testname;
figure,imshow(uint8(handles.contain_marker_dwt));title('含水印的图象(小波域)');
handles.pnsr=PSNR(handles.contain,handles.contain_marker_dwt);
title_string=strcat('含水印的图象(小波域) PNSR:',num2str(handles.pnsr));
title(title_string);
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)
handles.name_ex_dwt=extract_name(handles.contain,handles.contain_marker_dwt,handles.SORT_IND,handles.sel,handles.gau,handles.salt,handles.jpeg,handles.filt,handles.ang);
figure,imshow((handles.name_ex_dwt));title('提取的水印(小波域)');
guidata(hObject, handles);
% --- Executes on slider movement.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
[handles.contain_marker_dwt_times,handles.SORT_IND,handles.name1]=name_imbed;
figure,imshow(uint8(handles.contain_marker_dwt_times));title('含水印的图象(改进的小波域)');
handles.pnsr=PSNR(handles.contain,handles.contain_marker_dwt_times);
title_string=strcat('含水印的图象(改进的小波域) PNSR:',num2str(handles.pnsr));
title(title_string);
guidata(hObject, handles);
三、运行结果
完整代码或仿真咨询QQ1575304183
以上是关于图像隐写基于LSB+DCT实现数字水印嵌入提取带攻击测试matlab源码含GUI的主要内容,如果未能解决你的问题,请参考以下文章
图像隐写基于matlab LSB数字水印嵌入提取含Matlab源码 2412期
图像隐写基于matlab DWT数字水印嵌入+攻击+提取含Matlab源码 1759期
多种隐写基于matlab GUI LSB+DCT文本图片嵌入+提取含Matlab源码 1851期
图像隐写基于matlab DCT彩色数字水印嵌入提取含Matlab源码 077期