?? gui_wm.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];
%化為二進(jìn)制數(shù)據(jù)流
wbs=reshape(wb3,1,64*64*8);
%量化數(shù)組的長度
N=findobj('tag','edit1');
N=get(N,'string');
N=str2num(N);
%嵌入水印
o=double(o);
[WLoc,CA,CH,CV,CD]=Embed(o,wbs,N);
%重構(gòu)嵌入水印后的宿主圖像
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('重構(gòu)后的宿主圖像峰值信噪比為',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','正在提取水印,請稍候...');
%提取二進(jìn)制數(shù)據(jù)流
wbsr=Extract(r,WLoc,N);
%轉(zhuǎ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
%位圖重構(gòu)
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;
%進(jìn)行置亂逆變換,顯示水印
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('重構(gòu)后的宿主圖像峰值信噪比為',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
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -