image coding using ezw and qm coder

16
I I m m a a g g e e C C o o d d i i n n g g u u s s i i n n g g E E Z Z W W a a n n d d Q Q M M c c o o d d e e r r ECE 533 Project Report Ahuja, Alok + Singh, Aarti + + (50% contribution by each member)

Upload: faizal-haris

Post on 22-Nov-2015

11 views

Category:

Documents


2 download

DESCRIPTION

EZW coder

TRANSCRIPT

  • IImmaaggee CCooddiinngg uussiinngg EEZZWW aanndd QQMM ccooddeerr

    EECCEE 553333 PPrroojjeecctt RReeppoorrtt

    AAhhuujjaa,, AAllookk ++

    SSiinngghh,, AAaarrttii ++

    +(50% contribution by each member)

  • AAbbssttrraacctt

    This project involves Matlab implementation of the Embedded Zerotree Wavelet (EZW)

    coding algorithm followed by a QM coder. The Embedded Zerotree Wavelet (EZW)

    algorithm is a wavelet-based image compression algorithm that yields a fully embedded code

    as well as remarkable compression efficiency. An embedded code has the property that bits

    in the bit stream are generated in order of importance, hence the encoding can be truncated at

    any point to meet a specified bit rate. The output of the algorithm is a stream of symbols that

    can be further compressed using an adaptive binary arithmetic coder like the QM coder.

    OOvveerrvviieeww

    This report starts with a brief statement of the work performed the objectives, material

    studied and implemented. The main part of the report is divided into two broad sections

    covering the concepts behind EZW algorithm and the QM coder. Specifically we have tried

    to present issues that we found intricate, in a simpler manner and also tried to emphasize

    issues that are not clearly stated in the references. The next section contains the results

    followed by conclusion and discussion.

  • SSttaatteemmeenntt ooff WWoorrkk

    This project is somewhere between an implementation and study project. The project was

    started with an aim to understand and implement the EZW coding algorithm proposed by J.

    M. Shapiro (1). We tried to understand the scope of improvement in the EZW algorithm (2)

    and better ways to implement it eg. using SPIHT (3).

    Also we tried to focus on investigating adaptive arithmetic coders, specifically Q and QM

    coders that implemented finite precision representation for the interval size as well as

    provided computational simplicity. Starting with papers on adaptive binary arithmetic coder

    (7) to Q coders and its adaptive probability estimation (5), (6), we finally arrived at the QM

    coder (4), which is used in the JPEG standard for image compression. Due to the many

    improved features of the QM coder (as discussed later), we decided to implement it in

    Matlab. Results of a test sequence provided in (4) were reproduced.

    Finally, the QM-coder was interfaced and used alongwith the EZW coder.

  • EEZZWW bbaasseedd IImmaaggee CCooddiinngg

    The Embedded Zerotree Wavelet (EZW) algorithm is based on four key concepts

    (1) A discrete wavelet transform or hierarchical subband decomposition.

    (2) Prediction of absence of significant information in finer level wavelet coefficients

    based on coarser level coefficients.

    (3) Entropy-coded successive-approximation quantization.

    (4) Lossless data compression based on an adaptive arithmetic coder. (In this project, the

    coder used is the QM coder and we devote a separate section to it.)

    DDiissccrreettee WWaavveelleett TTrraannssffoorrmm is carried out by decomposing the image into four subbands

    (LL, LH, HL and HH) using separable wavelet filters and critically subsampling the output.

    The next coarser level of coefficients are obtained by decomposing the low frequency

    subband LL.

    Fig. A two-level subband decomposition (1)

    The goal of the transform is to produce coefficients that are decorrelated. This results in

    concentration of energy in a few coefficients while most are insignificant enough to be

    discarded, thus offering opportunity for compression.

  • SSiiggnniiff iiccaannccee MMaapp EEnnccooddiinngg The coefficients are compared to a threshold to determine if

    they are significant enough. The zerotree is based on the hypothesis that if a wavelet

    coefficient is insignificant with respect to a threshold T, then all wavelet coefficients of the

    same orientation in the same spatial location at finer scales are likely to be insignificant with

    respect to T.

    More specifically, in hierarchical subband decomposition, with the exception of the highest

    frequency subbands, every coefficient at the given level (parent) can be related to a set of

    coefficients (children)at next finer level of similar orientation and spatial location. For a

    given parent, the set of coefficients at all finer scales of similar orientation corresponding to

    the same location are called descendants.

    Fig. Parent-child dependencies (1)

    As can be seen each parent has three children except for the lowest frequency subband where

    the relationship is defined so that each parent node (in LL3) has three children (one each in

    HL3 , LH3 and HH3). Scanning of the coefficients is performed so that no child is scanned

    before its parent.

  • Given a threshold level T to determine whether or not a coefficient is significant, a

    coefficient is an element of a zerotree for threshold T if itself and all of its descendents are

    insignificant wrt T. An element of a zerotree is a zerotree root if it is not the descendent of a

    previously found zerotree root. Thus, a zerotree root indicates that the insignificance of the

    coefficients at all finer levels is completely predictable.

    Thus, the output of the EZW coder consists of the following symbols:

    1. Zerotree root, Z.

    2. Isolated zero, I. (means that coefficient is insignificant but has some significant

    descendents).

    3. Positive significant, P.

    4. Negative significant, N.

    Two more symbols L and H are generated which are discussed in the next section.

    SSuucccceessssiivvee--AApppprrooxx iimmaatt iioonn EEnnttrrooppyy--CCooddeedd QQuuaanntt iizzaatt iioonn is applied to achieve embedded

    coding. The encoding can be stopped when a specified bit-rate is met. Successive

    approximation quantization determines significance by starting with an initial threshold T0,

    chosen so that all transform coefficients are < 2T0. Successive thresholds are obtained as Ti =

    Ti-1/2. The encoding (and decoding) involves two main passes

    1. Dominant pass During a dominant pass, coefficients that have not yet been found to

    be significant are compared against the threshold, Ti. The scanning order follows

    treating parents before children, eg. raster scan, however those coefficients are

    omitted which are descendents of a zerotree root found before. If the coefficient is

    found significant, it is appended to the subordinate list, and is set to zero in the

  • wavelet transform array to prevent it from effecting future dominant passes at smaller

    thresholds. Coefficients found insignificant are coded as either zerotree root or

    isolated zero based on the previous discussion.

    2. Subordinate pass follows the dominant pass and outputs an L or H which further

    refines the specification of the magnitude of the coefficient put out to the decoder. i.e.

    it designates whether the coefficient is greater than Ti/2 (H) or less (L). Thus it

    reduces the uncertainty interval of the magnitude of the coefficient (or equivalently

    the quantizer step-size) by half. In the decoder, the reconstruction value used can be

    anywhere in that uncertainty interval. The magnitudes on the subordinate list are then

    sorted in decreasing order of magnitude.

    The process continues to alternate between dominant and subordinate passes where the

    threshold is halved Ti-1=Ti/2 before each dominant pass.

  • QQMM ccooddeerr

    The QM coder is a binary arithmetic coder, implying that it codes a stream of only two

    symbols 0 and 1. A source with mult iple symbols can also be coded by decomposing each

    symbol using a binary decision tree.

    Advantages of a binary arithmetic coder lie in that it generates compressed data as a finite-

    precision fraction which identifies an interval on the number line. Each symbol is encoded or

    decoded on the basis of a probability estimate which determines where the binary arithmetic

    coder splits the interval into two subintervals. The current symbol determines which

    subinterval becomes the new interval. When the size of the new interval drops below a

    minimum value, renormalization shifts the precision until it is greater than or equal to the

    minimum size. With each shift, a bit is produced for the compressed data stream.

    IInnppuutt bbiinnaarryy aallpphhaabbeett was generated using a tree of binary decisions. As noted previously

    the output of the EZW code was a stream of symbols containing the symbols: P, N, Z,

    I, H and L. The following binary decision tree was used based on the probability of

    occurrence of these symbols.

    L

    0 1

    H

    0 1

    0 1

    Z 0 1

    I 0 1

    P N

    Symbol stream

  • SSyymmbbooll oorrddeerriinngg aanndd iinntteerrvvaall ssuubbddiivv iissiioonn When the QM coder codes a binary decision (0

    or 1), it does not directly assign intervals to these symbols. Rather, it assigns intervals to the

    more probable symbol (MPS) and the less probable symbol (LPS) such that the LPS

    subinterval is always above the MPS subinterval.

    If the interval is A and the LPS probability estimate is Qe, the MPS probability estimate

    should ideally be (1-Qe). The lengths of the respective subintervals are then A Qe and

    ( )A Qe -1 . In the QM coder, code stream C points to the bottom of the current interval so

    that we need to add to the code stream only when an LPS occurs.

    CCooddiinngg aa ssyymmbbooll changes the interval and code stream as follows:

    After MPS: ( )QeAAC -= 1 unchanged is After LPS: ( ) QeAAQeACC =-+= 1

    RReennoorrmmaall iizzaatt iioonn is done by doubling (shifting left) A, and in accordance C, each time the

    interval falls below some minimum value (0.75). This enables finite precision representation

    C+A

    C+A.(1-Qe)

    C

    A.Qe

    A.(1-Qe)

    LPS

    MPS

  • for A by confining A within the limits 0.75-1.5 (since 1.5 is double of 0.75) and also aids to

    avoid the multiplication A.Qe as explained below.

    EElliimmiinnaatt iioonn ooff mmuulltt iipplliiccaatt iioonnss bbyy aapppprrooxx iimmaatt iioonn We desire to have A 1, so that A.Qe

    Qe. Keeping A bounded in the range 0.75 = A

  • intervals is interchanged. Since A-Qe < Qe < 0.5, both subintervals are less than 0.5 and

    renormalization must occur. Thus conditional exchange is always done after a

    renormalization.

    AAddaapptt iivvee PPrroobbaabbiilliittyy EEsstt iimmaatt iioonn The estimation process is based on a form of approximate

    counting in which the interval register normalization is used to estimate the MPS and LPS

    symbol counts. Whenever a renormalization occurs i.e. after every LPS and after every MPS

    that requires renormalization, a new probability estimate is obtained from a look-up table that

    provides a bigger Qe value when LPS renormalization occurs and a smaller Qe value when a

    MPS renormalization occurs. Thus, the distribution of probability estimates gets centered

    about the desired value.

    Markov-chain modeling of probability estimation The estimation process can be regarded

    as a markov-chain where each state represents one probability estimate (and also contains the

    sense of MPS) i.e. each state S can be thought of as a structure that contains a Qe(S) and a

    MPS(S). An index Index(S) points to the current state. Index(S) is initialized to the first state

    in the look-up table which corresponds to a Qe(S) ~ 0.5 (i.e. assuming initially that both

    symbols are almost equally probable). The state machine has mirror symmetry about the

    change in the sense of MPS. The look-up table used for the QM-coder estimation state

    machine thus consists of the state index, associated Qe, NMPS (Next state index after MPS

    renormalization), NLPS (Next state index after LPS) and Switch (if 1 indicates MPS sense

    needs to be switched).

  • Fig. Markov-chain modeling of probability estimation

    DDiiff ffeerreenncceess bbeettwweeeenn tthhee QQ aanndd QQMM ccooddeerr::

    1. Interval subdivision is improved in the QM coder by introducing conditional

    exchange where the sense of MPS is reversed if the MPS subinterval becomes less

    than the LPS subinterval. This leads to better compression.

    2. QM coder allows carry to be resolved completely before transmitting next byte thus

    preventing carry propagation problems.

    3. The QM coder uses an initial (fast attack states) to arrive quickly at approximately the

    right probability estimate and has more states in the probability estimation machine

    thus is more responsive to unstable statistics.

    Qe(Sj) MPS(Sj)

    Qe(Sk) MPS(Sk)

    Qe(Si) MPS(Si)

    Index(S)

    MPS renormalization

    Qe(Si) < Qe(Sj) < Qe(Sk)

    LPS

  • RReessuullttss

    The EZW algorithm was implemented and it can be seen how Wavelet transform

    concentrates all the energy in few significant coefficients. This feature is exploited by the

    zerotree coding to discard the insignificant coefficients and achieve good compression.

    The QM coder was also tested using the sequence given in (4) and detailed results compared

    with the one given. The QM coder works as a perfect lossless coder.

    The following compression ratios were obtained using a combination of the EZW and QM

    coder:

    Image Bits needed for image transmission Size x 8

    compressed stream length (output of QM coder)

    Compression ratio

    Fruits.png 512x512x8 = 2097152 129472 16.2

    Lena.bmp 512x512x8 = 2097152 138600 15.1

    Barbara.png 512x512x8 = 2097152 196789 10.6

    Clearly, lesser are the details the more is the compression efficiency since fewer coefficients

    are required to capture those details.

    Reconstruction results on images however could not be obtained due to some sign

    manipulation problem in the EZW decoder. However the magnitudes of the reconstructed

    coefficients agreed pretty well with the original coefficients.

  • CCoonncclluussiioonn

    This project was a good learning experience about the power of wavelet coding-based

    compression techniques for image compression. We were able to understand and reproduce

    the results in references (1) and (4) by implementing EZW and QM coder in Matlab.

    However, given the time, many concepts could not be explored and would form topic of

    future work. Investigating the effect of different wavelet filters on compression and

    reconstruction as well as the concept of embedded bit-coding to achieve the desired bit-rate

    are some of these. Further there are many other coders like MQ etc. that were not looked at

    and would be interesting to study and compare.

  • RReeffeerreenncceess

    EEZZWW::

    1. Embedded Image Coding using Zerotrees of Wavelet Coefficients, J. M. Shapiro, IEEE

    trans. on Sig. Proc., vol. 41, No. 12, Dec 1993, pp. 3445-3462.

    2. http://perso.wanadoo.fr/polyvalens/clemens/ezw/ezw.html

    3. A New, Fast, and Efficient Image Codec Based on Set Partitioning in Hierarchical

    Trees, A. Said and W. A. Pearlman, IEEE Trans. Circuits Syst. Video Technol., vol. 6,

    June 1996, pp. 243-249.

    QQMM--ccooddeerr::

    4. JPEG Still Image Data Compression Standard, W. B. Pennebaker & J. L. Mitchell.

    5. An overview of the basic principles of the Q-coder adaptive binary arithmetic coder,

    W. B. Pennebaker, et al., IBM J. Res. Develop., vol. 32, No. 6, Nov. 1988, pp. 717-725.

    6. Probability estimation for the Q-coder, W. B. Pennebaker and J. L. Mitchell, IBM J.

    Res. Develop., vol. 32, No. 6, Nov. 1988, pp. 737-751.

    7. An introduction to arithmetic coding, Glen G. Langdon, IBM J. Res. Develop., vol. 28,

    No. 2, March 1984, pp. 135-149.

  • SSuummmmaarryy ooff CCooddee

    EEZZWW eennccooddeerr ::

    Files required: EZW.m

    dominant_pass.m

    subordinate_pass.m

    process_LL_element.m

    process_element.m

    zerotree.m

    decodeEZW.m

    QQMM ccooddeerr ::

    Files required: Arithmetic_coder.m

    Code_MPS.m

    Code_LPS.m

    makestring.m

    Renorm.m

    Update_Index_S_after_LPS.m

    Update_Index_S_after_MPS.m

    byteout.m

    Arithmetic_decoder.m

    Cond_MPS_exchange_S.m

    Cond_LPS_exchange_S.m

    Renorm_d.m

    byte_in.m