[Project] Image and audio watermark based on matlab GUI LSB spatial domain, DWT, DCT algorithm [including Matlab source code 618]

1. Introduction

1 Introduction to LSB Algorithm
LSB is called Least Significant Bit (Least Significant Bit), 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 upper plane of the original image and the lowest plane representing the secret information form a new image containing hidden information.
Insert picture description here
The grayscaled image stores pixels in a single-channel format, and each pixel has a value between 0 and 255, and the bit plane of the pixel corresponds to each bit of the binary pixel. Take the above picture as an example, the value of a certain pixel is 78, its binary value is 01001110, and the bit weight decreases from left to right. The leftmost bit is the most significant bit (MSB, whose bit weight is 2 7 2^72
7
), and the rightmost bit The least significant bit (LSB, the bit weight is 2 0 2^02
0
). The same bits of each pixel are extracted to form a new plane, which is the so-called bit plane of the image. The LSB steganography algorithm, as its name suggests, embeds/hides information in the LSB, which is the lowest bit plane.

One thing to note is that when LSB is embedded, the carrier image format should be a grayscale image format

Take the famous Lena image as an example, the following is the original image of the grayscale image Lena: the
Insert picture description here
following is its various bit
Insert picture description here
-plane images , from left to right, from top to bottom, the bit planes decrease in turn: you can see that the higher the bit plane, the original image information contained The more, the greater the contribution to the gray value of the image, and the stronger the correlation between adjacent bits, and vice versa. The lowest bit plane of the LSB basically does not contain image information, similar to random noise/noise, so you can fill in the watermark/secret information here.

The embedding diagram is as follows: When
Insert picture description here
selecting different bit planes for embedding, the fidelity of the LSB algorithm:
Insert picture description here2 Algorithm principle
Generally speaking, the pictures we see are composed of small pixels, and all the pixels are placed together to form A big square, this big square is the image we see. A grayscale image (that is, what we usually call a black and white image) is composed of one layer of pixels, while a color image is composed of three layers of such grayscale images. Here is an example of a grayscale image. The reason why we can see black and white on the image is because the pixel value of each pixel is different. 0 means pure black, 255 means pure white, and gray is composed of the value between these two numbers. The closer to 0 the darker, the closer to 255 the whiter. Then why are 0 and 255? Because the computer is binary, it uses 8 bits to represent a pixel (more bits can also be used, so that the color grading of the image will be more, and the image will also take up more space, but the eyes of ordinary people are not Can't recognize so many colors, unless you are different from ordinary people), so the maximum value is 255 and the minimum is 0. lsb hides information based on the feature of binary system, because the human eye is not a very precise color or brightness perceptron, so fine-tuning the pixel gray level 1 up and down will not be noticed by the human eye, that is, modify 8. The smallest bit in a binary code. When we change the last bit of each pixel of the picture according to our ideas, it will show the information we want, but the user cannot see it, and it will not affect the content of the picture. This is the lsb digital watermark.
3 The basic characteristics of the LSB algorithm:
LSB is a large-capacity data hiding algorithm
. The robustness of LSB is relatively poor (when the stego image encounters signal processing, such as: noise, lossy compression, etc., it will be used when extracting embedded information. loss)
embedding method 4 common LSB algorithm:
secret information at the lowest bit-plane continuously embedded in the end, the rest of no treatment (typically software MandelSteg)
secret information continuously embedded in the end at the lowest bit-plane, the rest of the randomized treatment (also known as Desertification treatment, typical software PGMStealth)
Secret information continuously embedded in the least significant bit plane, and once the low plane and is simultaneously embedded in the least significant bit plane and a secondary lower plane
secret information is embedded in the least significant bit plane, and so the lowest bit-plane is embedded completely embedded after re-embedding times lower plane of
the secret information at the lowest Random embedding in bit plane The
above five methods, when the embedding capacity is different, the robustness is different

Second, the source code

function varargout = gui(varargin)
% GUI MATLAB code for gui.fig
%      GUI, by itself, creates a new GUI or raises the existing
%      singleton*.
%
%      H = GUI returns the handle to a new GUI or the handle to
%      the existing singleton*.
%
%      GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI.M with the given input arguments.
%
%      GUI('Property','Value',...) creates a new GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before gui_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to gui_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

% Last Modified by GUIDE v2.5 05-Jan-2017 11:30:52

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = gui_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 open_original.
function open_original_Callback(hObject, eventdata, handles)
global Raw_image
[filename, pathname]=uigetfile({
    
    '*.bmp','ALL FILES(*.*)'},'选择图片文件');
if isequal([filename pathname],[0,0])
    return;
end
str=[pathname filename];%选择的文件路径和文件名
Raw_image=imread(str);
axes(handles.axes1);
imshow(Raw_image);
% hObject    handle to open_original (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in open_wartermark.
function open_wartermark_Callback(hObject, eventdata, handles)
global mark
[filename, pathname]=uigetfile({
    
    '*.bmp','ALL FILES(*.*)'},'选择图片文件');
if isequal([filename pathname],[0,0])
    return;
end
str=[pathname filename];%选择的文件路径和文件名
mark=imread(str);
axes(handles.axes2);
imshow(mark);
% hObject    handle to open_wartermark (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in embed.
function embed_Callback(hObject, eventdata, handles)
global rawImage
global mark
global embedImage
global markr
global markg
global markb
global alpha
size=512;
block=8;
blocknum=size/block;%每行或每列块的个数
Number=size*size/(block*block);%总块的个数
%alpha=1/3000;  %归一化
T1=3;
rawImage=zeros(size,size);
embedImage=zeros(size,size);
embedImager=zeros(size,size);
embedImageg=zeros(size,size);
embedImageb=zeros(size,size);
bw=zeros(size,size);
block_dct1=zeros(block,block);


imshow(mark);
markr=double(mark(:,:,1));
markg=double(mark(:,:,2));
markb=double(mark(:,:,3));




rawImage = imread('lena.bmp');
rawImager=double(rawImage(:,:,1));
rawImageg=double(rawImage(:,:,2));
rawImageb=double(rawImage(:,:,3));

%==================R分量的嵌入========================
for m=1:blocknum
for n=1:blocknum
        x=(m-1)*block+1;
        y=(n-1)*block+1;
        block_dct1=rawImager(x:x+block-1,y:y+block-1); 
        block_dct1=dct2(block_dct1);
        bw_8_8=bw(x:x+block-1,y:y+block-1);
        block_dct1(1,1)=block_dct1(1,1)*(1+alpha*(markr(m,n)));
        block_dct1=idct2(block_dct1);
        embedImager(x:x+block-1,y:y+block-1)=(block_dct1); 
end
end

%======================G分量的嵌入=================

for m=1:blocknum
for n=1:blocknum
        x=(m-1)*block+1;
        y=(n-1)*block+1;
        block_dct1=rawImageg(x:x+block-1,y:y+block-1); 
        block_dct1=dct2(block_dct1);
        bw_8_8=bw(x:x+block-1,y:y+block-1);
        block_dct1(1,1)=block_dct1(1,1)*(1+alpha*(markg(m,n)));
        block_dct1=idct2(block_dct1);
        embedImageg(x:x+block-1,y:y+block-1)=(block_dct1); 
end
end

%====================B分量的嵌入====================
for m=1:blocknum
for n=1:blocknum
        x=(m-1)*block+1;
        y=(n-1)*block+1;
        block_dct1=rawImageb(x:x+block-1,y:y+block-1); 
        block_dct1=dct2(block_dct1);
        bw_8_8=bw(x:x+block-1,y:y+block-1);
        block_dct1(1,1)=block_dct1(1,1)*(1+alpha*(markb(m,n)));
        block_dct1=idct2(block_dct1);
        embedImageb(x:x+block-1,y:y+block-1)=(block_dct1); 
end
end

Three, running results

Insert picture description here
Insert picture description here
Insert picture description here

Four, remarks

Complete code or write on behalf of adding QQ 1564658423

Guess you like

Origin blog.csdn.net/TIQCmatlab/article/details/115184712