阅读 26

【语音隐写】基于matlab GUI LSB语音信号数字水印【含Matlab源码 619期】

一、简介

1 LSB算法简介
LSB全称为 Least Significant Bit(最低有效位),是一种简单而有效的数据隐藏技术。LSB隐写的基本方法是用欲嵌入的秘密信息取代载体图像的最低比特位,原来的图像的高位平面与代表秘密信息的最低平面组成含隐蔽信息的新图像。
在这里插入图片描述
灰度化的图像为单通道格式存储像素,每个像素值在0~255内,而像素的位平面则是对应二进制的像素的各个位。以上图为例,某个像素的值为78,其二进制01001110,从左到右位权依次降低,最左边为最高有效位(MSB,其位权为 2 7 2^72
7
),最右边位最低有效位(LSB,位权为2 0 2^02
0
)。把每个像素的相同位抽取出来组成一个新的平面,就是所谓的图的位平面。而LSB隐写算法,如其名字,是在LSB也就是最低位平面进行信息嵌入/隐藏。

需要注意的一点是,LSB嵌入的时候,载体图像格式应该为灰度图格式

以著名的Lena图为例,一下是灰度图Lena原图:
在这里插入图片描述
下面是其各个位平面图,从左到右、从上到下位平面依次降低:
在这里插入图片描述
可以看到,位平面越高包含的原图像信息越多,对图像的灰度值贡献越大,并且相邻比特的相关性也越强,反之则相反。LSB最低位平面基本上不包含图像信息了,类似随机的噪点/噪声,因此,可以在此处填入水印/秘密信息。

嵌入示意图如下:
在这里插入图片描述
选取不同位平面嵌入时,LSB算法的保真度:
在这里插入图片描述2 算法原理
通俗来讲我们看到的图片都是由一个个小的像素点来构成的,所有像素点摆在一起,构成一个大方块,这个大方块就是我们所见的图像。灰度图像(也就是我们平时所说的黑白图像)是由一层像素点组成的,而彩色图像是由三层这样的灰度图像组成的。这里拿灰度图像举例,我们之所以能在图像上看到黑色和白色,是因为每个像素点的像素值不同。0表示纯黑,255表示纯白,灰色就是由这两个数字之间的值构成。越靠近0越黑,越靠近255越白。那为什么是0和255呢?因为计算机是二进制,它会用8个比特来表示一个像素点(也可以用更多的比特,这样图像的颜色分级就越多,同时图像也会占用更大的空间,但是普通人的眼睛并不能辨认这么多的颜色,除非你异于常人),所以最大值是255,最小是0。lsb就是基于2进制这一特点来隐藏信息的,因为人眼并不是很精密的颜色或亮度的感知器,所以把像素灰度上下微调1是不会被人眼察觉的,也就是修改8位二进制码中最小的一位。当我们把图片每个像素的最后一位按照我们的想法改变,使他表现为我们想要的信息,但用户却不能看出,也不会影响图片的内容。这就是lsb数字水印。
3 LSB算法的基本特点:
LSB是一种大容量的数据隐藏算法
LSB的鲁棒性相对较差(当stego图像遇到信号处理,比如:加噪声,有损压缩等,在提取嵌入信息时会丢失)
4 常见LSB算法的嵌入方法:
秘密信息在最低位平面连续嵌入至结束,余下部分不作任何处理(典型软件MandelSteg)
秘密信息在最低位平面连续嵌入至结束,余下部分随机化处理(也称沙化处理,典型软件PGMStealth)
秘密信息在最低位平面和次低位平面连续嵌入,并且是同时嵌入最低位平面和次低位平面
秘密信息在最低位平面嵌入,等最低位平面嵌入完全嵌入之后,再嵌入次低位平面
秘密信息在最低位平面随机嵌入
以上五种方式,当嵌入容量不同时,鲁棒性不同

二、源代码

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
复制代码

三、运行结果

在这里插入图片描述

四、备注

版本:2014a
完整代码或代写加1564658423

文章分类
人工智能
文章标签