编程语言
首页 > 编程语言> > 【图像压缩】基于小波变换图像压缩含Matlab源码

【图像压缩】基于小波变换图像压缩含Matlab源码

作者:互联网

1 简介

数字图像压缩技术是使用最少的数据信息表示原图像的一种信息处理技术.本文先从小波变换的分解与重构分析原理入手,使用基于Matlab的小波变换算法进行数字图像压缩处理,获取较大的图像压缩比,处理后的图像清晰度高、效果好.​

2 部分代码

function varargout = multi_wavelet(varargin)

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name',       mfilename, ...

                   'gui_Singleton',  gui_Singleton, ...

                   'gui_OpeningFcn', @multi_wavelet_OpeningFcn, ...

                   'gui_OutputFcn',  @multi_wavelet_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 multi_wavelet is made visible.

function multi_wavelet_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 multi_wavelet (see VARARGIN)

% Choose default command line output for multi_wavelet

handles.output = hObject;

% Update handles structure

guidata(hObject, handles);

% UIWAIT makes multi_wavelet wait for user response (see UIRESUME)

% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.

function varargout = multi_wavelet_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)

global I ;

[fname,pname]=uigetfile('*.*');

I=imread(strcat(pname,'\',fname));

[m,n,k]=size(I);

if k~=1

I=rgb2gray(I);

end

I=double(I);

axes(handles.axes1);

imshow(mat2gray(I));

title('原始图像的灰度图');

% --- 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 = get(hObject,'String') returns popupmenu1 contents as cell array

%        contents{get(hObject,'Value')} returns selected item from popupmenu1

global I ;

w1=get(handles.popupmenu1,'value')

switch w1   %选择小波基

case 1

   w2= 'bior 3.7';

case 2

    w2='bior 1.1';

case 3    

    w2='bior 1.3';

case 4    

    w2='bior 1.5';

case 5    

   w2='bior 2.2';

case 6   

   w2='bior 2.4';

case 7   

   w2= 'bior 2.6';

case 8   

    w2='bior 2.8';

case 9    

    w2='bior 3.1';

case 10    

    w2='bior 3.3';

case 11    

    w2='bior 3.5';

case 12    

    w2='bior 3.9';

case 13    

    w2='bior 4.4';

case 14    

    w2='bior 5.5';

case 15    

    w2='bior 6.8';

case 16    

    w2='db1';

case 17    

    w2='db4';

case 18    

    w2='db15';

end

disp('压缩前图像的大小');%显示文字

whos('I')           %显示图像属性

% 进行二维小波变换 'bior3.7'

[a,b] = wavedec2(I, 3,w2); % 分三层,wavedec2:2维多层小波分解

% 提取各层低频信息

c1 = appcoef2( a, b,w2, 1 );%提取二维小波分解低频系数

axes(handles.axes18);

imshow(c1, []);

title('第一层低频部分:');

ca1=wcodemat(c1,440,'mat',0);   %对第一层信息进行量化编码

axes(handles.axes2);

imshow(ca1, []);

title('第一次压缩后图像:');

disp('第一次压缩图像的大小');%显示文字

whos('ca1');

c2= appcoef2( a, b,w2, 2 );

axes(handles.axes19);

imshow(c2, []);

title('第二层低频部分:');

ca2=wcodemat(c2,440,'mat',0);   %对第一层信息进行量化编码

axes(handles.axes6);

imshow(ca2, []);

title('第二次压缩后图像:');

disp('第二次压缩图像的大小');%显示文字

whos('ca2');

c3= appcoef2( a, b,w2, 3 );

axes(handles.axes20);

imshow(c3, []);

title('第三层低频部分:');

ca3=wcodemat(c3,440,'mat',0);   %对第一层信息进行量化编码

axes(handles.axes10);

imshow(ca3, []);

title('第三次压缩后图像:');

disp('第三次压缩图像的大小');%显示文字

whos('ca3');

% 提取水平高频信息

c1 = detcoef2('h', a, b, 1 );

axes(handles.axes3);

imshow(c1, []);

title('第一层水平方向高频部分:');

c2= detcoef2('h', a, b, 2 );

axes(handles.axes7);

imshow(c2, []);

title('第二层水平方向高频部分:');

c3= detcoef2('h', a, b, 3 );

axes(handles.axes12);

imshow(c3, []);

title('第三层水平方向高频部分:');

% 提取垂直高频信息

c1 = detcoef2('v', a, b, 1 );

axes(handles.axes4);

imshow(c1, []);

title('第一层垂直方向高频部分:');

c2= detcoef2('v', a, b, 2 );

axes(handles.axes8);

imshow(c2, []);

title('第二层垂直方向高频部分:');

c3= detcoef2('v', a, b, 3 );

axes(handles.axes13);

imshow(c3, []);

title('第三层垂直方向高频部分:');

% 提取对角高频信息

c1 = detcoef2('d', a, b, 1 );

axes(handles.axes5);

imshow(c1, []);

title('第一层对角方向高频部分:');

c2= detcoef2('d', a, b, 2 );

axes(handles.axes9);

imshow(c2, []);

title('第二层对角方向高频部分:');

c3= detcoef2('d', a, b, 3 );

axes(handles.axes14);

imshow(c3, []);

title('第三层对角方向高频部分:');

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

3 仿真结果

4 参考文献

[1]贾厚林. Matlab环境下基于小波变换的图像压缩研究[J]. 无锡商业职业技术学院学报, 2005, 5(1):3.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

标签:case,imshow,title,axes,图像压缩,handles,源码,Matlab,w2
来源: https://blog.csdn.net/qq_59747472/article/details/122786866