⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gui_wm.m

📁 实现小波数字水印
💻 M
字号:
function varargout = GUI_WM(varargin)
% GUI_WM M-file for GUI_WM.fig
%      GUI_WM, by itself, creates a new GUI_WM or raises the existing
%      singleton*.
%
%      H = GUI_WM returns the handle to a new GUI_WM or the handle to
%      the existing singleton*.
%
%      GUI_WM('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI_WM.M with the given input arguments.
%
%      GUI_WM('Property','Value',...) creates a new GUI_WM or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before GUI_WM_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to GUI_WM_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 GUI_WM

% Last Modified by GUIDE v2.5 12-Jun-2008 12:37:15

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GUI_WM_OpeningFcn, ...
                   'gui_OutputFcn',  @GUI_WM_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 GUI_WM is made visible.
function GUI_WM_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 GUI_WM (see VARARGIN)

global w
global o

%读取宿主图像
o=imread('lena.jpg');
axes(handles.axes1);
imshow(o);
set(handles.axes1,'xtick',[],'ytick',[],'ztick',[],'box','off');
axis image off;

%读取水印
w=imread('watermark.jpg');
axes(handles.axes3);
imshow(w);
set(handles.axes3,'xtick',[],'ytick',[],'ztick',[],'box','off');
axis image off;

axes(handles.axes2);
set(handles.axes2,'xtick',[],'ytick',[],'ztick',[],'box','off');
axis image off;

axes(handles.axes4);
set(handles.axes4,'xtick',[],'ytick',[],'ztick',[],'box','off');
axis image off;

axes(handles.axes5);
set(handles.axes5,'xtick',[],'ytick',[],'ztick',[],'box','off');
axis image off;

axes(handles.axes6);
set(handles.axes6,'xtick',[],'ytick',[],'ztick',[],'box','off');
axis image off;

% Choose default command line output for GUI_WM
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes GUI_WM wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = GUI_WM_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)

global Ln
global o
global w
global wl
global N
global r
global PSNRH
global WLoc

set(handles.text7,'string','正在置乱水印,请稍候...');

%水印置乱
Ln=10;
wl=Arnold(w,Ln);
axes(handles.axes4);
imshow(wl);
set(handles.axes4,'xtick',[],'ytick',[],'ztick',[],'box','off');
axis image off;

set(handles.text7,'string','正在嵌入水印,请稍候...');

%位图分解
wb=Bitdecom(wl);

%重新组合
wb1=[wb(:,:,1) wb(:,:,2) wb(:,:,3) wb(:,:,4)];
wb2=[wb(:,:,5) wb(:,:,6) wb(:,:,7) wb(:,:,8)];
wb3=[wb1;wb2];

%化为二进制数据流
wbs=reshape(wb3,1,64*64*8);

%量化数组的长度
N=findobj('tag','edit1');
N=get(N,'string');
N=str2num(N);

%嵌入水印
o=double(o);
[WLoc,CA,CH,CV,CD]=Embed(o,wbs,N);

%重构嵌入水印后的宿主图像
r=IDWT2(CA,CH,CV,CD,'haar');
r=uint8(r);
axes(handles.axes2);
imshow(r);
set(handles.axes2,'xtick',[],'ytick',[],'ztick',[],'box','off');
axis image off;

%计算宿主图像峰值信噪比
r=double(r);
PSNRH = sum(sum((r-o).^2))/512/512;
PSNRH = 10*log10(255^2/PSNRH);
PSNRH=sprintf('%.2f',PSNRH);
MSE{1}='水印嵌入完毕!';
MSE{2}=strcat('重构后的宿主图像峰值信噪比为',PSNRH,'DB');
set(handles.text7,'string',MSE);

% --- 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)

global Ln
global wl
global N
global r
global PSNRH
global WLoc

set(handles.text7,'string','正在提取水印,请稍候...');
%提取二进制数据流
wbsr=Extract(r,WLoc,N);

%转为为矩阵
wb3r=reshape(wbsr,128,256);

%重新组合
for i=1:8
    rm=ceil(i/4);
    cn=i-(rm-1)*4;
    wbr(:,:,i)=wb3r(1+64*(rm-1):64+64*(rm-1),1+64*(cn-1):64+64*(cn-1));
end

%位图重构
wlr=Bitrecon(wbr);

%计算水印峰值信噪比
wl=double(wl);
PSNRW = sum(sum((wlr-wl).^2))/64/64;
PSNRW = 10*log10(255^2/PSNRW);

%显示提取的置乱水印
wlr=uint8(wlr);
axes(handles.axes5);
imshow(wlr);
set(handles.axes5,'xtick',[],'ytick',[],'ztick',[],'box','off');
axis image off;

%进行置乱逆变换,显示水印
wr=iArnold(wlr,Ln);
axes(handles.axes6);
imshow(wr);
set(handles.axes6,'xtick',[],'ytick',[],'ztick',[],'box','off');
axis image off;

PSNRW=sprintf('%.2f',PSNRW);
MSE{1}=strcat('重构后的宿主图像峰值信噪比为',PSNRH,'DB');
MSE{2}=strcat('提取的水印峰值信噪比为',PSNRW,'DB');
set(handles.text7,'string',MSE);



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -