| Contents | Index |
| On this page… |
|---|
You can generate MATLAB code to reproduce GUI–based 2-D wavelet packet compression at the command line. You must perform this operation in the Wavelet 2-D - - Compression tool. You must first compress your image before you can enable the File > Generate Matlab Code (Compression Process) operation.
Enter wavemenu at the MATLAB command prompt.
Select Wavelet Packet 2-D.
Select File > Load > Example Analysis > Indexed Images, and load the tire.

Using the default parameter settings, click Best Tree.

Click Compress.
Set Select thresholding method to Bal.sparsity-norm (sqrt).
Click Compress.

File > Generate Code (Compression Process) generates the following code.
function [XCMP,wptCMP] = func_compress_wp2d(X)
% FUNC_COMPRESS_WP2D Saved Compression Process.
% X: matrix of data
% -----------------
% XCMP: matrix of compressed data
% wptCMP: wavelet packet decomposition (wptree object)
% Analysis parameters.
%---------------------
Wav_Nam = 'haar';
Lev_Anal = 2;
Ent_Nam = 'shannon';
Ent_Par = 0;
% Compression parameters.
%-----------------------
% meth = 'sqrtbal_sn';
sorh = 'h'; % Specified soft or hard thresholding
thrSettings = {sorh,'nobest',16.499999999999886,1};
roundFLAG = true;
% Decompose using WPDEC2.
%-----------------------
wpt = wpdec2(X,Lev_Anal,Wav_Nam,Ent_Nam,Ent_Par);
% Nodes to merge.
%-----------------
n2m = [2 3];
for j = 1:length(n2m)
wpt = wpjoin(wpt,n2m(j));
end
% Compression using WPDENCMP.
%----------------------------
[XCMP,wptCMP] = wpdencmp(wpt,thrSettings{:});
if roundFLAG , XCMP = round(XCMP); end
if isequal(class(X),'uint8') , XCMP = uint8(XCMP); endSave the generated MATLAB code as func_compress_wp2d.m in a folder on the MATLAB search path, and execute the following code.
load tire;
[XCMP,wptCMP] = func_compress_wp2d(X);Save the compressed image from the Wavelet 2-D -- Compression tool as compressed_tire.mat in a folder on the MATLAB search path. Use File > Save > Compressed Image to save the compressed image.
Execute the following code to compare the command line and GUI result.
load compressed_tire.mat;
norm(XCMP-X,2)![]() | Generating MATLAB Code for 1-D Wavelet Packet Denoising and Compression | GUI Reference | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |