wcompress

True compression of images using wavelets

Syntax

wcompress('c',X,SAV_FILENAME,COMP_METHOD)
wcompress(...,'ParName1',ParVal1,'ParName2',ParVal2,...)
[COMPRAT,BPP] = wcompress('c',...)
XC = wcompress('u',SAV_FILENAME)
XC = wcompress('u',SAV_FILENAME,'plot')
XC = wcompress('u',SAV_FILENAME,'step')

Description

The wcompress command performs either compression or uncompression of grayscale or truecolor images.

More theoretical information on true compression is in True Compression for Images of the Wavelet Toolbox™ User's Guide.

Compression

wcompress('c',X,SAV_FILENAME,COMP_METHOD) compresses the image X using the compression method COMP_METHOD.

The compressed image is saved in the file SAV_FILENAME. X can be either a 2-D array containing an indexed image or a 3-D array of uint8 containing a truecolor image.

wcompress('c',FILENAME,...) loads the image X from the file FILENAME which is a MATLAB® Supported Format (MSF) file: MAT-file or other image files (see imread).

wcompress('c',I,...) converts the indexed image X = I{1} to a truecolor image Y using the colormap map = I{2} and then compresses Y.

The valid compression methods are divided in three categories.

  1. Progressive Coefficients Significance Methods (PCSM):

    MATLAB Name

    Compression Method Name

    'ezw'

    Embedded Zerotree Wavelet

    'spiht'

    Set Partitioning In Hierarchical Trees

    'stw'

    Spatial-orientation Tree Wavelet

    'wdr'

    Wavelet Difference Reduction

    'aswdr'

    Adaptively Scanned Wavelet Difference Reduction

    'spiht_3d'

    Set Partitioning In Hierarchical Trees 3D for truecolor images

For more details on these methods, see the references and especially Walker and also Said and Pearlman.

  1. Coefficients Thresholding Methods (CTM-1):

    MATLAB Name

    Compression Method Name

    'lvl_mmc'

    Subband thresholding of coefficients and Huffman encoding

For more details on this method, see the Strang and Nguyen reference.

  1. Coefficients Thresholding Methods (CTM-2):

    MATLAB Name

    Compression Method Name

    'gbl_mmc_f'

    Global thresholding of coefficients and fixed encoding

    'gbl_mmc_h'

    Global thresholding of coefficients and Huffman encoding

      Note   The Discrete Wavelet Transform uses the periodized extension mode. Each of the two dimensions of the image must be a power of 2.

All the compression methods use parameters which have default values. You can change these values using the following syntax:

wcompress(...,'ParName1',ParVal1,'ParName2',ParVal2,...)

Some of the parameters are related to display or to data transform functionalities. The others are linked to the compression process itself.

Data transform parameters

  • 'ParName' = 'wname' or 'WNAME' sets the wavelet name.

    ParVal is a string (see waveletfamilies). The default for is bior4.4

  • 'ParName' = 'level' or 'LEVEL' sets the level of decomposition.

    ParVal is an integer such that: 1 level levmax which is the maximum possible level (see wmaxlev).

    The default level depends on the method:

         - for PCSM methods level is equal to levmax.

         - for CTM methods level is equal to fix(levmax/2)

  • ParName' = 'it' or 'IT' sets Image type Transform.

    ParVal must be one of the following strings:

    'n' : no transformation (default), image type (truecolor or grayscale) is automatically detected.

    'g' : grayscale transformation type.

    'c' : color transformation type (RGB uint8).

  • 'ParName' = 'cc' or 'CC' sets Color Conversion parameter if X is a truecolor image.

    ParVal must be one of the following strings:

    'rgb' or 'none' : No conversion (default).

    'yuv' : YUV color space transform.

    'klt' : Karhunen-Loeve transform.

    'yiq' : YIQ color space transform.

    'xyz' : CIEXYZ color space transform.

Parameter for Progressive Coefficients Significance Methods (PCSM)

  • 'ParName' = 'maxloop' or 'MAXLOOP' sets the maximum number of steps for the compression algorithm.

    ParVal must be a positive integer or Inf (default is 10).

Parameters for Coefficients Thresholding Methods (CTM-1)

Either of the following parameters may be used:

  • 'ParName' = 'bpp' or 'BPP' sets the bit-per-pixel ratio.

    ParVal must be such that 0 ParVal 8 (grayscale) or 24 (truecolor).

  • 'ParName' = 'comprat' or 'COMPRAT' sets the compression ratio.

    ParVal must be such that 0 ParVal 100.

Parameters for Coefficients Thresholding Methods (CTM-2)

Two parameters may be used. The first is related to the threshold and the second is the number of classes for quantization.

The first one may be chosen among the five following parameters:

  • 'ParName' = 'threshold' or 'THRESHOLD' sets the threshold value for compression.

    ParVal must be a positive (or zero) real number.

  • 'ParName' = 'nbcfs' or 'NBCFS' sets the number of preserved coefficients in the wavelet decomposition.

    ParVal must be an integer such that: 0 ParVal total number of coefficients of wavelet decomposition.

  • 'ParName' = 'percfs' or 'PERCFS' sets the percentage of preserved coefficients in the wavelet decomposition.

    ParVal must be a real number such that: 0 ParVal 100.

  • 'ParName' = 'bpp' or 'BPP' sets the bit-per-pixel ratio.

    ParVal must be such that: 0 ParVal 8 (grayscale) or 24 (truecolor)

  • 'ParName' = 'comprat' or 'COMPRAT' sets the compression ratio.

    ParVal must be such that: 0 ParVal 100.

The second parameter sets the number of classes for quantization:

  • 'ParName' = 'nbclas' or 'NBCLAS' sets the number of classes.

    ParVal must be a real number such that: 2 ParVal 200.

Display parameter

  • 'ParName' = 'plotpar' or 'PLOTPAR' sets the plot parameter.

    ParVal must be one of the following strings or numbers:

    'plot' or 0: plots only the compressed image.

    'step' or 1: displays each step of the encoding process (only for PCSM methods).

[COMPRAT,BPP] = wcompress('c',...) returns the compression ratio COMPRAT and the bit_per_pixel ratio BPP.

Uncompression

XC = wcompress('u',SAV_FILENAME) uncompresses the file SAV_FILENAME and returns the image XC. Depending on the initial compressed image, XC can be a 2-D array containing either an indexed image or a 3-D array of uint8 containing a truecolor image.

XC = wcompress('u',SAV_FILENAME,'plot') plots the uncompressed image.

XC = wcompress('u',SAV_FILENAME,'step') shows the step-by-step uncompression, only for PCSM methods.

Examples

% Example 1: Compression and uncompression using 
% basic parameters.
%
% This example demonstrates first how to compress the jpeg 
% image arms.jpg using the 'stw' compression method and
% save it to the file: 'comp_arms.wtc'. 

wcompress('c','arms.jpg','comp_arms.wtc','stw');

% Then, it shows how to load the stored image from
% the file 'comp_arms.wtc' and to display the step by 
% step uncompression leading to the final image below.

wcompress('u','comp_arms.wtc','step');

% Example 2: Compression and uncompression using 
% advanced parameters.
%
% This example demonstrates how to compress a jpeg
% image using the 'aswdr' compression method and
% save it to the file: 'woodstatue.wtc'. 
% During the compression process 3 parameters are used:
% - Conversion color (cc) set to Karhunen-Loeve transform 'klt'
% - Maximum number of loops (maxloop) set to 11
% - Plot type (plotpar) set to step by step display
% By the way two performance indicators are displayed:
% the compression ratio (cr) and the bit-per-pixel ratio (bpp).

[cr,bpp] = wcompress('c','woodstatue.jpg','woodstatue.wtc', ...
             'aswdr','cc','klt','maxloop',11,'plotpar','step')

cr =

    3.0701

bpp =

    0.7368

% Then, it shows how to load the stored image from the
% file 'woodstatue.wtc' and to display the step by step
% uncompression process.

wcompress('u','woodstatue.wtc','step');

delete('woodstatue.wtc')

% Example 3: Compression and uncompression of a grayscale image 
% and computed MSE and PSNR error values.
%
% Two measures are commonly used to quantify the error between
% two images: the Mean Square Error(MSE) and the Peak Signal
% to Noise Ratio (PSNR) which is expressed in decibels.
%
% This example demonstrates how to compress the mask image using
% the 'spiht' compression method and save it to the 'mask.wtc'
% file. 

load mask;       
[cr,bpp] = wcompress('c',X,'mask.wtc','spiht','maxloop',12)

cr =
    2.8336

bpp =

    0.2267

% Then, it shows how to load the stored image from the file
% 'mask.wtc', uncompress it and delete the file 'mask.wtc'.

Xc = wcompress('u','mask.wtc');
delete('mask.wtc')

% The orginal and compressed images are displayed.
colormap(pink(255))
subplot(1,2,1); image(X);  title('Original image')
axis square
subplot(1,2,2); image(Xc); title('Compressed image')
axis square

% Finally the MSE and the PSNR are computed.

D = abs(X-Xc).^2;
mse  = sum(D(:))/numel(X)

mse =
   33.6564

psnr = 10*log10(255*255/mse)

psnr =

   32.8601
% Example 4: Compression and uncompression of a truecolor image 
% and computed MSE and PSNR error values.
% Compression parameters are the same as those used for example 3,
% but using the 'spiht_3d' method give better performance yet. 

X = imread('wpeppers.jpg');
[cr,bpp] = wcompress('c',X,'wpeppers.wtc','spiht','maxloop',12)

cr =
    1.6527

bpp =
    0.3966

Xc = wcompress('u','wpeppers.wtc');
delete('wpeppers.wtc')
subplot(1,2,1); image(X);  title('Original image'), axis square
subplot(1,2,2); image(Xc); title('Compressed image'), axis square

D = abs(double(X)-double(Xc)).^2;
mse  = sum(D(:))/numel(X)

mse =

    26.7808

psnr = 10*log10(255*255/mse)

psnr =

   33.8526

References

Christophe, E., C. Mailhes, P. Duhamel (2006), "Adaptation of zerotrees using signed binary digit representations for 3 dimensional image coding," EURASIP Journal on Image and Video Processing, 2007, to appear in the special issue on Wavelets in Source Coding, Communications, and Networks, Paper ID 54679.

Misiti, M., Y. Misiti, G. Oppenheim, J.-M. Poggi (2007), Wavelets and their applications, ISTE DSP Series.

Said A., W.A. Pearlman (1996), "A new, fast, and efficient image codec based on set partitioning in hierarchical trees," IEEE Trans. on Circuits and Systems for Video Technology, Vol. 6, No. 3, pp. 243–250.

Shapiro J.M. (1993), "Embedded image coding using zerotrees of wavelet coefficients",P IEEE Trans. Signal Proc., Vol. 41, No. 12, pp. 3445–3462.

Strang, G.; T. Nguyen (1996), Wavelets and Filter Banks, Wellesley-Cambridge Press.

Walker J.S. (1999), "Wavelet-Based Image Compression," University of Wisconsin, Eau Claire, Wisconsin, USA, , Sub-chapter of CRC Press book: Transform and Data Compression. A Primer on Wavelets and Their Scientific Applications.

See Also

| |

Was this topic helpful?