1, Introduction
1 Introduction to LSB algorithm
The full name of LSB is Least Significant Bit (LSB), which is a simple and effective data hiding technology. 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-order plane of the original image and the lowest plane representing the secret information form a new image containing hidden information.
The grayed image stores pixels in a single channel format, each pixel value is within 0 ~ 255, and the bit plane of the pixel is each bit of the corresponding binary pixel. As shown in the above figure, the value of a pixel is 78, and its binary 01001110 decreases from left to right. The leftmost is the most significant bit (MSB), and its bit weight is 2 7 2 ^ 72
7
), rightmost bit, least significant bit (LSB), bit weight 2 0 2 ^ 02
0
). The same bit of each pixel is extracted to form a new plane, which is the so-called bit plane of the graph. The LSB steganography algorithm, as its name, embeds / hides information in the LSB, that is, the lowest plane.
It should be noted that when LSB is embedded, the carrier image format should be gray image format
Taking the famous Lena diagram as an example, the following is the original gray-scale Lena diagram:
The following are the bit plans, which are lowered from left to right and from top to bottom:
It can be seen that the higher the bit plane contains more original image information, the greater the contribution to the gray value of the image, and the stronger the correlation of adjacent bits, on the contrary. The LSB lowest plane basically does not contain image information, which is similar to random noise / noise. Therefore, watermark / secret information can be filled here.
The embedding diagram is as follows:
Fidelity of LSB algorithm when different bit planes are selected for embedding:
2 algorithm principle
Generally speaking, the pictures we see are composed of small pixels. All pixels are placed together to form a large square, which is the image we see. Gray image (that is, what we usually call black-and-white image) is composed of one layer of pixels, while color image is composed of three layers of such gray images. Take the gray image as an example. The reason why we can see black and white on the image is that the pixel values of each pixel are different. 0 means pure black, 255 means pure white, and gray is composed of the value between the two numbers. The closer to 0, the darker, and the closer to 255, the whiter. So why 0 and 255? Because the computer is binary, it will use 8 bits to represent a pixel (more bits can also be used, so that the image will have more color ratings, and the image will occupy more space, but ordinary people's eyes can't recognize so many colors unless you are different from ordinary people), so the maximum value is 255 and the minimum value is 0. lsb is based on binary system to hide information. Because the human eye is not a very precise color or brightness sensor, it will not be detected by the human eye to fine tune the pixel gray up and down by 1, that is, modify the smallest bit in the 8-bit binary code. When we change the last bit of each pixel of the picture according to our idea, so that it can be displayed as the information we want, but the user can't see it and won't affect the content of the picture. This is lsb digital watermarking.
3. Basic characteristics of LSB algorithm:
LSB is a large capacity 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. Embedding methods of common LSB algorithms:
The secret information is continuously embedded in the lowest plane until the end, and the rest is not processed (typical software MandelSteg)
The secret information is continuously embedded in the lowest plane until the end, and the rest is randomized (also known as sanding, typical software PGMStealth)
Secret information is continuously embedded in the lowest level plane and the sub low level plane, and is embedded in the lowest level plane and the sub low level plane at the same time
The secret information is embedded in the lowest plane, and then embedded in the second lowest plane after the lowest plane is fully embedded
Secret information is randomly embedded in the lowest plane
The robustness of the above five methods is different when the embedding capacity is different
2, Source code
unction 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 22-Apr-2021 13:43:30 % 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','Select original bmp Picture file'); 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','Select embed hidden file'); 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 Represents that bit plane,1 Is the lowest bit global x y z ary = 1; cover_object = rgb2gray(x); %Read my photo information to get gray image information cover_object_ll = bitget(cover_object, ary); %Get the last bit subplot(handles.axes5); %Wake up a window imshow(cover_object); %Display the gray image formed by the original image
3, Operation results
4, matlab version and references
1 matlab version
2014a
2 references
[1] Cai Limei MATLAB image processing -- theory, algorithm and example analysis [M] Tsinghua University Press, 2020
[2] Yang Dan, Zhao Haibin, long Zhe Detailed explanation of MATLAB image processing example [M] Tsinghua University Press, 2013
[3] Zhou pin MATLAB image processing and graphical user interface design [M] Tsinghua University Press, 2013
[4] Liu Chenglong Proficient in MATLAB image processing [M] Tsinghua University Press, 2015
[5] Liang Xin Research on color image digital watermarking algorithm based on DWT and SVD [J] Computer and digital engineering 2019,47(08)
[6] Zhang Xiujuan, Zhu Chunwei An image digital watermarking algorithm based on DWT-SVD [J] Digital technology and application 2017,(10)