【图像压缩】哈达玛变换图像压缩【含GUI Matlab源码 845期】

在这里插入图片描述

⛄一、简介

沃尔什-哈达玛变换(Walsh-Hadmard Transform,WHT),是一种典型的非正弦函数变换,采用正交直角函数作为基函数,具有与傅里叶函数类似的性质,图像数据越是均匀分布,经过沃尔什-哈达玛变换后的数据越是集中于矩阵的边角上,因此沃尔什变换具有能量集中的性质,可以用于压缩图像信息。

Matlab中的Hadamard函数:
格式:H=hadamard( n ) ,返回一个 n * n的hadamard矩阵。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

⛄二、部分源代码

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

% Last Modified by GUIDE v2.5 18-Jun-2009 20:25:20

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(‘gui_Name’, mfilename, …
‘gui_Singleton’, gui_Singleton, …
‘gui_OpeningFcn’, @hadamard_encoding_OpeningFcn, …
‘gui_OutputFcn’, @hadamard_encoding_OutputFcn, …
‘gui_LayoutFcn’, [] , …
‘gui_Callback’, []);
if nargin & isstr(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 hadamard_encoding is made visible.
function hadamard_encoding_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 hadamard_encoding (see VARARGIN)
cr = 0.5;
I = imread(‘lena.bmp’);
axes(handles.axes1);
imshow(I);
I = double(I)/255;
t = hadamard(8);
fftcoe = blkproc(I,[8 8],‘P1xP2’,t,t);
coevar = im2col(fftcoe,[8 8],‘distinct’);
coe = coevar;
[y,ind] = sort(coevar);
[m,n] = size(coevar);
snum = 64-64cr;
for i = 1:n
coe(ind(1:snum),i) = 0;
end
B2 = col2im(coe,[8 8],[512 512],‘distinct’);
I2 = blkproc(B2,[8,8],'P1
xP2’,t,t);
I2 = I2./(8
8);
axes(handles.axes2);
imshow(I2);
e = double(I) - double(I2);
[m,n]=size(e);
erms = sqrt(sum(e(😃.^2)/(m*n));
set(handles.erms_edit,‘string’,erms);
set(handles.cr_edit,‘string’,0.5);
% Choose default command line output for hadamard_encoding
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

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

% — Outputs from this function are returned to the command line.
function varargout = hadamard_encoding_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 during object creation, after setting all properties.
function image_pop_menu_CreateFcn(hObject, eventdata, handles)
% hObject handle to image_pop_menu (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
set(hObject,‘BackgroundColor’,‘white’);
else
set(hObject,‘BackgroundColor’,get(0,‘defaultUicontrolBackgroundColor’));
end

% — Executes on selection change in image_pop_menu.
function image_pop_menu_Callback(hObject, eventdata, handles)
% hObject handle to image_pop_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
val = get(hObject,‘value’);
str = get(hObject,‘string’);
cr = str2num(get(handles.cr_edit,‘string’));
switch str{val}
case ‘Lena’
I = imread(‘lena.bmp’);
case ‘Cameraman’
I = imread(‘cameraman.tif’);
case ‘Peppers’
I = imread(‘peppers.bmp’);
case ‘Fingerprint’
I = imread(‘fingerprint.jpg’);
case ‘Licenceplate’
I = imread(‘licenceplate.jpg’);
case ‘Cloudy’
I = imread(‘cloudy.tif’);
end
axes(handles.axes1);
imshow(I);
I = double(I)/255;
t = hadamard(8);
fftcoe = blkproc(I,[8 8],‘P1xP2’,t,t);
coevar = im2col(fftcoe,[8 8],‘distinct’);
coe = coevar;
[y,ind] = sort(coevar);
[m,n] = size(coevar);
snum = 64-64cr;
for i = 1:n
coe(ind(1:snum),i) = 0;
end
B2 = col2im(coe,[8 8],size(I),‘distinct’);
I2 = blkproc(B2,[8,8],'P1
xP2’,t,t);
I2 = I2./(8
8);
axes(handles.axes2);
imshow(I2);
e = double(I) - double(I2);
[m,n]=size(e);
erms = sqrt(sum(e(😃.^2)/(m*n));
set(handles.erms_edit,‘string’,erms);
set(handles.cr_edit,‘string’,0.5);
% Hints: contents = get(hObject,‘String’) returns image_pop_menu contents as cell array
% contents{get(hObject,‘Value’)} returns selected item from image_pop_menu

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

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,‘BackgroundColor’,‘white’);
else
set(hObject,‘BackgroundColor’,get(0,‘defaultUicontrolBackgroundColor’));
end

function cr_edit_Callback(hObject, eventdata, handles)
% hObject handle to cr_edit (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,‘String’) returns contents of cr_edit as text
% str2double(get(hObject,‘String’)) returns contents of cr_edit as a double

% — Executes on button press in apply_button.
function apply_button_Callback(hObject, eventdata, handles)
% hObject handle to apply_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cr = str2num(get(handles.cr_edit,‘string’));
I = getimage(handles.axes1);
I = double(I)/255;
t = hadamard(8);
fftcoe = blkproc(I,[8 8],‘P1xP2’,t,t);
coevar = im2col(fftcoe,[8 8],‘distinct’);
coe = coevar;
[y,ind] = sort(coevar);
[m,n] = size(coevar);
snum = 64-floor(64*cr);
for i = 1:n
coe(ind(1:snum),i) = 0;
end

⛄三、运行结果

在这里插入图片描述

⛄四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1]陈小来,胡炳樑,钱情明,刘彩芳.哈达玛变换光谱仪压缩系统研究[J].电子设计工程. 2012,20(03)

3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
沃尔什-哈达变换(Walsh-Hadamard Transform,WHT)是一种线性变换,用于在信号处理和数字图像处理领域中进行频谱分析、数据压缩和编码等操作。它是基于哈达矩阵的一种变换方法。 沃尔什-哈达变换可以对长度为2的幂的序列进行变换变换后的结果为相同长度的序列。它的核心思想是通过对输入序列中的每对元素进行加法和减法操作,得到变换后的序列。变换的过程可以递归地进行,将序列划分为越来越小的子序列。 下面是沃尔什-哈达变换的基本步骤: 1. 初始化:将长度为N的输入序列表示为一个N维向量。 2. 若N = 1,则变换结束,输出结果即为输入序列。 3. 否则,将输入序列划分为两个长度为N/2的子序列。 4. 对每个子序列应用沃尔什-哈达变换。 5. 将两个子序列的变换结果按照一定规则组合,得到长度为N的变换结果。 具体来说,在第4步中,对每个子序列应用沃尔什-哈达变换的方法是将其分成两部分,分别进行加法和减法操作,并将结果按原序列的顺序排列。例如,对于长度为8的输入序列[1, 0, 1, 0, 0, 1, 0, 1],可以按照如下方式进行变换: ``` [1, 0, 1, 0, 0, 1, 0, 1] -> [1, 1, 0, 0] + [1, -1, 0, 0] -> [2, 0, 0, 0] ``` 最终得到变换后的结果为[2, 0, 0, 0]。 沃尔什-哈达变换具有快速计算的性质,并且在数据压缩、图像编码和傅里叶变换等方面有广泛的应用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Matlab领域

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值