[Project] Digital watermark based on matlab GUI LSB voice signal [Contains Matlab source code 619]

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 do 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. Lost)
4 The embedding method of common LSB algorithm: the
secret information is continuously embedded in the lowest bit plane to the end, and the remaining part is not processed (typical software MandelSteg). The
secret information is continuously embedded in the lowest bit plane to the end, and the remaining part is randomized (also called 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 = untitled1(varargin)
% UNTITLED1 M-file for untitled1.fig
%      UNTITLED1, by itself, creates a new UNTITLED1 or raises the existing
%      singleton*.
%
%      H = UNTITLED1 returns the handle to a new UNTITLED1 or the handle to
%      the existing singleton*.
%
%      UNTITLED1('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in UNTITLED1.M with the given input arguments.
%
%      UNTITLED1('Property','Value',...) creates a new UNTITLED1 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled1_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled1_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 untitled1

% Last Modified by GUIDE v2.5 21-Nov-2012 21:12:41

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = untitled1_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 selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
%        contents{
    
    get(hObject,'Value')} returns selected item from popupmenu1


% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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


% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array
%        contents{
    
    get(hObject,'Value')} returns selected item from popupmenu2


% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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


% --- 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 fs;
global x1;
global xmax;
global t1;
global l1;
var=get(handles.popupmenu2,'value');
switch var
    case 1
        [x1,fs]=audioread('music1.wav'); 
        cy2=x1(:,1);
    case 2
        [x1,fs]=audioread('music2.wav'); 
  
end
%从底部到顶部,底部的平面有更惊喜的灰度细节,而高阶的比特平面则包含了大多数的数据。而比特分层的实现就是依靠阈值处理函数:
xmax=max(abs(x1));                          %计算最大幅度
xmin=min(abs(x1));                          %计算最小幅度
l1=size(x1);                                %计算出载频的总长度l1,便于FFT分析频谱
t1=(0:length(x1)-1)/fs;
y1=fft(x1,fs);                              %对信号做FFT变换
f=fs*(0:8191)/fs;
axes(handles.axes1);
plot(t1,x1)                                  %做原始语音信号的时域图形
grid on;axis tight;
title('原始语音信号');
xlabel('time(s)');
ylabel('幅度');
axes(handles.axes2);
plot(f,abs(y1(1:8192)))                      %做原始语音信号的FFT频谱图
grid on;axis tight;
title('原始语音信号FFT频谱')
xlabel('HZ');
ylabel('幅度');
sound(x1)

% --- 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)

global fs;
global x1;
global sy;
global lhsy;
global lhx1;
global qrh;
global QRH;
global xmax;
global symax;
global l1;
global l2;
global t1;
global t2;
global qshuiyin;
global Qshuiyin;
var=get(handles.popupmenu1,'value');
switch var
    case 1
        [sy,fs]=audioread('shuiyin1.wav');
    case 2
        [sy,fs]=audioread('shuiyin2.wav');
  
end

Three, running results

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/115184794