Implementing The SPIHT Algorithm in MATLAB
Implementing The SPIHT Algorithm in MATLAB
Abstract
New algorithms for image compression based on wavelets have been recently
developed1-4. One of the most efficient algorithms is the Set Partitioning in Hierarchical
Trees (SPIHT) algorithm1. Most of the implementations known to date for the SPIHT
algorithm have been done in C (or C++). This paper describes a MATLAB
implementation of the SPIHT algorithm where wavelet functions are directly called from
the wavelet toolbox, hence no code is needed, whereas in the C (C++) implementation,
one has to write and test wavelet function code. In the SPIHT algorithm zero-trees are
generated by the wavelet transform followed by a tree-search. Typically in C (or C++),
pointers are use to perform such a search. However, in MATLAB, the tree-search can be
performed using a structure array, which can be generated at run-time. In addition, the
SPIHT algorithm orders the wavelet coefficients according to a significance test and
stores this information in three separate lists. These lists are also easily implemented
using MATLAB’s structure arrays. MATLAB also allows working efficiently at bit-level
operations for bit-plane transmission of wavelet coefficients. Because of the wide use of
MATLAB in the academic community and the robustness of its toolboxes, particularly
the wavelets toolbox, students’ can easily modify the SPIHT m-files to accommodate
their research projects in the areas of image and signal processing. MATLAB sample
code and simulation results on image compression examples will be presented.
I. Introduction
New algorithms for image compression based on wavelets have been recently
developed1-4. These methods have resulted in practical advances such as: superior low-
bit rate performance, continuous-tone and bit-level compression, lossless and lossy
compression, progressive transmission by pixel accuracy and resolution, region-of-
interest coding and others. One of the most efficient procedures that fulfill the above
goals is the Set Partitioning in Hierarchical Trees (SPIHT) algorithm1. This algorithm
bases its efficiency in key concepts like: a) partial ordering of wavelet coefficients by
magnitude, with transmission of order by a subset partitioning that is replicated at the
decoder, b) ordered bit-plane transmission of refinement bits and c) exploitation of self-
similarity of the image wavelet coefficients across different scales.
Most of the implementations known to date for the SPIHT algorithm have been done in C
(or C++). This paper describes a MATLAB implementation of the SPIHT algorithm.
MATLAB is widely used in the academic community as one of the teaching platforms for
signal and image processing. It has a robust set of toolboxes, particularly the wavelets
One of the most efficient algorithms in the area of image compression is the Set
Partitioning in Hierarchical Trees (SPIHT). In essence it uses a sub-band coder, to
produce a pyramid structure where an image is decomposed sequentially by applying
power complementary low pass and high pass filters and then decimating the resulting
images. These are one-dimensional filters that are applied in cascade (row then column)
to an image whereby creating a four-way decomposition: LL (low-pass then another low
pass), LH (low pass then high pass), HL (high and low pass) and finally HH (high pass
then another high pass). The resulting LL version is again four-way decomposed, as
shown in Figure 1. This process is repeated until the top of the pyramid is reached.
LL HL
HL
LH HH
LH HH
and each of them recursively maintains a spatial similarity to its corresponding four off-
spring. This pyramid structure is commonly known as spatial orientation tree. For
example, Figure 2 shows the similarity among sub-bands within levels in the wavelet
space6. If a given coefficient at location (i,j) is significant in magnitude then some of its
descendants will also probably be significant in magnitude. The SPIHT algorithm takes
advantage of the spatial similarity present in the wavelet space to optimally find the
location of the wavelet coefficient that are significant by means of a binary search
algorithm.
The SPIHT algorithm sends the top coefficients in the pyramid structure using a
progressive transmission scheme. This scheme is a method that allows obtaining a high
quality version of the original image from the minimal amount of transmitted data. As
illustrated in Figure 3, the pyramid wavelet coefficients are ordered by magnitude and
then the most significant bits are transmitted first, followed by the next bit plane and so
on until the lowest bit plane is reached. It has been shown that progressive transmission
can significantly reduced the Mean Square Error (MSE) distortion for every bit-plane
sent1.
where Ci, j is the wavelet coefficient at the nth bit plane, at location (i,j)of the τ m subset
of pixels, representing a parent node and its descendants. If the result of the significance
test is yes an S flag is set to 1 indicating that a particular test is significant. If the answer
is no, then the S flag is set to 0, indicating that the particular coefficient is insignificant.
This is represented by equation (3).
Bit sign s s s s s s s s s
Row
MSB 5 1 1 0 0 0 0 0 0 0
4 1 1 0 0 0 0 0
3 1 1 1 0 0
2 0
1
LSB 0
Wavelets coefficients which are not significant at the nth bit-plane level may be
significant at (n-1)th bit-plane or lower. This information is arranged, according to its
significance, in three separate lists: list of insignificant sets (LIS), the list of insignificant
pixels (LIP) and the list of significant pixels (LSP). In the decoder, the SPIHT algorithm
replicates the same number of lists. It uses the basic principle that if the execution path of
any algorithm is defined by the results on its branching points, and if the encoder and
decoder have the same sorting algorithm then the decoder can recover the ordering
information easily1.
{ }
1. Initialization: Output n= n = log 2 (max (i, j ) Ci, j ; set the LSP as empty list
and add the coordinates (i, j ) ∈ H to the LIP and only those with descendents also
to the LIS, as type A entries.
2. Sorting Pass
3. Refinement Pass: For each entry (i, j ) in the LSP except those included in the
last sorting pass (i.e. with the same n), output the nth most significant bit of Ci, j
4. Quantization step update: decrement n by 1 and go to step 2
Most of SPIHT implementation algorithm has been coded in C or C++. However, the
authors feel that MATLAB and its wavelet toolbox offer an interesting option to
implement the SPIHT algorithm5,7. The MATLAB is very stable platform regarding code
and offers a rich variety of wavelets functions, which students can experiment with. In
addition, MATLAB offers two new data structures, cell arrays and structure arrays that
can be used to search for the coefficients in the trees generated by the wavelet
decomposition. These data structures allow grouping dissimilar but related arrays into a
Structure arrays can access elements by names called fields7. These arrays can have a
number of dimensions. For example
LIS(1).significance=1;
LIS(1).location=[2 5];
LIS(2).significance=0
LIS(2).location =[8 10]
In the above example the structure array LIS has two fields: significance and location
with different data types, a singleton and 1-D array. In addition the structure array itself
has two entries LIS(1) and LIS(2). The LIS array fields and entries can then be
accessed easily.
Using structure arrays the search through the wavelet tree was implemented with a
standard stack search shown below, where T is the top of the tree:
FindMax(T)
(if T==NULL)
error;
else
SÅCreate New Stack;
Push(S,Root(T));
MaxÅ Root(T);
While (notEmptyStack(S));
TempÅ Pop(S);
If data(Temp) > Data (Max);
Max Å Temp;
Push all of the children of Temp onto S;
Endwhile;
Return Max;
End FindMax
This generic algorithm sequentially traverses the tree until it finds the maximum node, it
then efficiently pushes or pops elements on the top of the stack as it traverses the tree
thus keeping the size of the stack at minimum. The MATLAB version of this algorithm is
presented in appendix A, where a structure array was used to define the stack.
The LIS, the LIP and the LSP lists were also built using structure arrays. These arrays are
especially useful when handling the refinement pass as these lists can grow or shrink at
run-time. The sample code below shows the creation of part of LIS type A at the top of
the pyramid
end
end
The LIS, the LIP and the LSP lists can grow dynamically at run-time. For instance in the
above example a new entry can be added to the structure array LIS by incrementing
count_LISA as follows:
count_LISA= count_LISA+1;
LIS(count_LISA).myIndex(1,1)={[cellrow cellcol]};
The SPIHT algorithm was implemented using MATLAB. Our preliminary results are as
follows, Figure 4 shows the original Lena image, Figure 5 illustrates the wavelet pyramid
tree created by using the bi-orthogonal wavelet (bior4.4 in MATLAB [2]), and Figure 5
shows the recovered image using up to 5th bit plane (from the maximum of 13 bit-planes).
The recovered image is visually very close to the original image. If all the bit planes are
used then the original image is recovered completely (up to rounding errors). Although
the MATLAB version of the SPIHT runs slow no attempt was done to optimize the code
as for instance in8,9. The authors’ aim was to have an implementation ready for students
to experiment with. Students’ familiarity with MATLAB and accessible tools in it will
allow them to easily modify the code and reduce development time. For instance one
method is already explored in10 by modifying the SPIHT algorithm using Lossy/Lossless
region of interest (ROI) coding. In a similar fashion our students can modify the
algorithm to include different methods of ROI coding.
V. Conclusions
We have implemented the SPIHT algorithm using MATLAB and its wavelet toolbox.
Students’ familiarity with this platform is what guided us through this development.
Further research includes the optimization of the code as in8, improvements for region of
Bibliography
1. A. Said and W. Pearlman, “A New, fast and Efficient Image Code Based on Set
Partitioning in Hierarchical Trees,” IEEE Transactions on Circuits and Systems for
Video technology, Vol. 6, No. 3, June 1996.
5. Misiti, Y, Misiti, G. Oppenheim, J.M. Poggi, Wavelet Toolboox, For use with
MATLAB. The Mathworks Inc., Natick, MA.
9. VCDemo at http://www-it.et.tudelft.nl/~inald/vcdemo/
ALDO MORALES
Dr. Morales received his electronic engineering degree with distinction from the University of Tarapaca,
Arica, Chile (formerly Northern University) and M.S. and Ph.D. degrees in electrical and computer
engineering from the State University of New York at Buffalo. Since August 2001 he has been working as
an associate professor of electrical engineering at Penn State Harrisburg. From 1990 to August 2001 he
was with Penn State DuBois first as assistant professor and then as an associate professor of engineering.
His research interests are in mathematical morphology, digital image processing, computer vision, and
neural networks. Dr. Morales has been involved in teaching microprocessors applications, computer
languages, software application and local area networks for many years. In 1996 Dr. Morales was honored
by the Institute of Electrical and Electronic Engineers (IEEE) with the Best Paper Award at the
International Asia Pacific Conference on Circuits and Systems for the paper " Basis Matrix Representation
of Morphological Filters with N-Dimensional Structuring Elements."
SEDIG AGILI
Dr. Agili received his BS, MS, and Ph.D. in Electrical and Computer Engineering from Marquette
University in 1986, 1989, and 1996, respectively. As a student, he was awarded fellowships from
Marquette University and the U.S. Department of Education. Upon receiving his Ph.D., he joined the
faculty at Marquette University where he taught several courses in electrical engineering and conducted
research in the area of electro-optic devices, fiber optic communication and fiber optic sensors. In fall of
2001, he joined the electrical engineering and electrical engineering technology programs at Penn State
University, Capital College. Currently has is teaching and conducting research in electronic
communications, fiber optic communications and fiber optic sensors. He has authored several articles
published in journals and conference proceedings, and made presentations at many conferences and
seminars. He also worked for Astronaut Corporation of America in Milwaukee, Wisconsin where he was
involved in designing optical projection and heads-up display systems. He is a member of the Institute of
Electrical and Electronic Engineers, American Society for Engineering Education, and Sigma Xi.