A list,

1 Introduction to LSB algorithm

LSB, short for Least Significant Bit, is a simple and effective data hiding technique. The basic method of LSB steganography is to replace the lowest bit of the carrier image with the secret information to be embedded. The high level plane of the original image and the lowest plane representing the secret information form a new image containing hidden information.



The grayscale image stores pixels in a single channel format, with each pixel value ranging from 0 to 255, and the pixel’s bitplane is each bit of the corresponding binary pixel. For example, a pixel with a value of 78, binary 01001110, has a decreasing bit weight from left to right, and the most significant bit (MSB) on the left has a bit weight of 2 72 ^72

7

), the rightmost bit is the least significant bit (LSB, bit weight is 20 02 ^02

0

). The same bits of each pixel are extracted to form a new plane, which is called the bitplane of the graph. The LSB steganography, as its name suggests, inserts/hides information in the LSB, the lowest level plane.

It should be noted that when LSB is embedded, the carrier image format should be grayscale

Taking the famous Lena graph as an example, the following is the original Lena graph of grayscale graph:



Here is the plan of its bits, descending from left to right and top to bottom:



It can be seen that the higher the bit plane is, the more information of the original image is contained, the greater the contribution to the gray value of the image is, and the stronger the correlation between adjacent bits is, and vice versa. The LSB lowest level plane basically contains no image information, like random noise/noise, so you can fill in watermark/secret information here.

The embedding diagram is as follows:



When different bit planes are selected for embedding, the fidelity of LSB algorithm is as follows:

2 Algorithm Principle

Generally speaking, the picture we see is made up of small pixels, all of which are put together to form a big square, and this big square is the image we see. A grayscale image (also known as a black and white image) consists of one layer of pixels, while a color image consists of three layers of grayscale images. Take grayscale image as an example. The reason why we can see black and white on the image is that each pixel has a different pixel value. 0 is pure black, 255 is pure white, and gray is made up of the value between these two numbers. The closer you get to 0, the darker you get, and the whiter you get to 255. So why 0 and 255? Because the computer is binary, it will use 8 bits to represent a pixel (you can also use more bits, so the more the color of the image classification, image will occupy more space at the same time, but the eyes of ordinary people do not recognize so much color, different from ordinary people unless you), so the maximum value is 255, the lowest is 0. LSB hides information based on the binary system. Because human eyes are not very sophisticated color or brightness sensors, a slight change of pixel gray level by 1 is not detected by human eyes, that is, modifying the smallest bit of 8-bit binary code. When we change the last bit of each pixel of the image to the way we want it, it shows the information we want, but the user can’t see it, and it doesn’t affect the content of the image. This is the LSB digital watermark.

3. Basic characteristics of LSB algorithm:

LSB is a high-volume data hiding algorithm

The robustness of LSB is relatively poor (when steGO image encounters signal processing, such as adding noise, lossy compression, etc., it will be lost when extracting embedded information)

4 common EMBEDDING methods of LSB algorithm:

The secret information is continuously embedded in the lowest plane until the end, and the rest is not processed (typical MandelSteg software)

The secret information is continuously embedded in the lowest plane until the end, and the rest of the processing is randomized (also known as desertification processing, typical software PGMStealth).

The secret information is embedded in the least – and sub- low – order plane continuously and simultaneously

The secret information is embedded in the lowest level plane. After the lowest level plane is fully embedded, the secret information is embedded in the second level plane

The secret information is randomly embedded in the lowest plane

The above five methods have different robustness when the embedding capacity is different

Ii. Source code

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);
Copy the code

3. Operation results













Complete code or simulation consultation QQ1575304183