Generate MATLAB Code for 2-D Wavelet Packet Denoising and Compression
2-D Wavelet Packet Compression
You can generate MATLAB® code to reproduce app–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
waveletAnalyzer
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
toBal.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); end
Save 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 Wavelet Analyzer app result.
load compressed_tire.mat; norm(XCMP-X,2)