function varargout = LSB(varargin)
% LSB MATLAB code for LSB.fig
% LSB, by itself, creates a new LSB or raises the existing
% singleton*.
%
% H = LSB returns the handle to a new LSB or the handle to
% the existing singleton*.
%
% LSB('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in LSB.M with the given input arguments.
%
% LSB('Property','Value',...) creates a new LSB or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before LSB_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to LSB_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 LSB
% Last Modified by GUIDE v2.5 09-Jun-2020 12:42:32
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @LSB_OpeningFcn, ...
'gui_OutputFcn', @LSB_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 LSB is made visible.
function LSB_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 LSB (see VARARGIN)
% Choose default command line output for LSB
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes LSB wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = LSB_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)
[filename,filepath]=uigetfile('.bmp','选择原始bmp图片文件');
if(filename==0)
return;
end
global originalfile x
originalfile= strcat(filepath,filename);
x=imread(originalfile);
subplot(handles.axes1);
imshow(originalfile);
% --- 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)
[filename,filepath]=uigetfile('.bmp','选择嵌入隐秘文件');
if(filename==0)
return;
end
global secretfile y
secretfile= strcat(filepath,filename);
y=imread(secretfile);
subplot(handles.axes2);
imshow(secretfile);
% --- 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)
%ary 表示那个比特面,1是最低比特位
global x y z
ary = 1;
cover_object = rgb2gray(x); %读取本人照片信息得到灰度图信息
cover_object_ll = bitget(cover_object, ary); %得到最后1位比特
subplot(handles.axes5); %唤醒一个窗口
imshow(cover_object); %展示原图像形成的灰度图
subplot(handles.axes6);
imshow(255*cover_object_ll); %最低位左移到最高位,展示原图像的最低位
message = im2bw(y, graythresh(y)); %将指纹图像变为二值图
subplot(handles.axes7);
imshow(message);%展示隐秘信息的二值图
Mc = size(cover_object, 1); %Height 读取图片的大小
Nc = size(cover_object, 2); %Width
message = imresize(message, [Mc Nc]); %使被隐藏图片和载体图片等长宽
z = cover_object;
%使得载体图片的最后一个比特位,与被隐藏图片的数据相等
for ii = 1 : Mc
for jj = 1 : Nc
if ii*jj < Mc * Nc %小于指纹信息的图片大小
if cover_object_ll(ii, jj) ~= message(ii, jj) %左右两端不相等,结果为一
if cover_object_ll(ii, jj) == 1
z(ii, jj) = bitset(z(ii,jj), ary, 0); %不相等改为0
else
z(ii, jj) = bitset(z(ii,jj), ary, 1);
end
end
end
end
end
subplot(handles.axes3);%显示嵌入隐秘信息后的图片
imshow(z);
subplot(handles.axes8);%显示隐秘信息的最低位
watermarked_image_ll = bitget(z, ary);
imshow(255 * watermarked_image_ll);
figure;
imshow(z);
title('watermarked picture');
saveas(gcf, '加密后.bmp');
%title('watermarked picture`s lowest bit');
% --- 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)
file='加密后.bmp'
water_pic = imread(file); %待提取图像
water_pic_1 = bitget(water_pic, 1); %得到最后1位比特
subplot(handles.axes4);%显示提取出的隐秘信息
imshow(255*water_pic_1);
figure
imshow(255*water_pic_1);
saveas(gcf,'提取出.bmp');