True compression of images using wavelets
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')
The wcompress
command
performs either compression or uncompression of grayscale or truecolor
images.
More theoretical information on true compression is in Wavelet Compression for Images of the Wavelet Toolbox™ User's Guide.
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
.
You must have write permission in the current working directory
or MATLAB® will change directory to tempdir
and
write the .wtc
file in that directory. X
can
be either a 2-D array containing an indexed image or a 3-D array of uint8
containing
a truecolor image. Both the row and column size of the image must
be powers of two.
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
.
Data written to .wtc
files uses uint64
precision.
In releases previous to R2016b, data was written using uint32
.
If your code is affected adversely by this change, use the legacy
option
to compress and uncompress your data using the previous behavior.
wcompress('c',X,SAV_FILENAME,COMP_METHOD,'legacy')
The valid compression methods are divided in three categories.
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.
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.
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 |
The Discrete Wavelet Transform uses the periodized extension mode.
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.
'ParName'
= 'wname'
or 'WNAME'
sets
the wavelet name.
ParVal
is a character vector or string scalar (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:
'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:
'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.
'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).
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
.
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
.
'ParName'
= 'plotpar'
or 'PLOTPAR'
sets
the plot parameter.
ParVal
must be one of the following:
'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
.
XC = wcompress('u',SAV_FILENAME)
uncompresses
the file SAV_FILENAME
, which contains the compressed
image, 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.
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.