+ All Categories
Home > Documents > Run Length Encoding By Surovit Roy

Run Length Encoding By Surovit Roy

Date post: 16-Oct-2015
Category:
Upload: surovit-roy
View: 57 times
Download: 1 times
Share this document with a friend
Description:
This a Full Repirt on RLE with Algorithm.If you want the code please call me on 8087937710.This is my Final Year Project.
Popular Tags:

of 48

Transcript
  • 5/26/2018 Run Length Encoding By Surovit Roy

    1/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 1

    Project Report On

    IMAGE COMPRESSION

    B Tech (Electronics and Telecommunication)

    By

    Honey Soni

    Surovit Roy

    Rahul Virmani

    Under the Guidance of

    Prof. Sachin A. Sonawane

    Department of Electronics and Telecommunication Engineering

    S.V.K.MsNMIMS, Mukesh Patel School of Technology

    Management and Engineering.

    APRIL 2014

  • 5/26/2018 Run Length Encoding By Surovit Roy

    2/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 2

    ACKNOWLEDGEMENT

    The success of our project depends largely on the encouragement and guidelines of

    many others. We take this opportunity to express our gratitude to the people who have been

    instrumental in the successful completion of this seminar.

    We would like to show my greatest appreciation to Prof. Sachin A. Sonawane, our

    project guide, Electronics and Telecommunication Department. I cant thank him enough

    for their tremendous support and help. Without his encouragement and guidance this

    project would not have materialized. We are also highly obliged to our Dean who has beenthe guiding light and a great pillar of support for making this project see the day of light.

    We am grateful for the guidance, support and help received from other memberswho contributed to this project which have been vital for the success of this project.

    Honey Soni

    Surovit RoyRahul Virmani

  • 5/26/2018 Run Length Encoding By Surovit Roy

    3/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 3

    ABSTRACT

    The aim of the project is to implement the Run length Encoding Transform to any

    time varying signal and analyze the signal obtained. Run-length encoding (RLE) is a very

    simple form of data compression in which runs of data (that is, sequences in which thesame data value occurs in many consecutive data elements) are stored as a single data value

    and count, rather than as the original run. This is most useful on data that contains many

    such runs; for example, simple graphic images such as icons and line drawings.

    The ultimate goal is to implement its typical and most common application to an

    image and show excellent results of compression using wavelets and how information in

    the image is retained.

    There are two closely interlinked reasons for compression.

    Firstly, to reduce the size of stored or transmitted files to manageable sizes, or to

    reduce the time it would take to transmit these files.

    Secondly, to reduce the real-time bandwidth required to transmit time-sensitive

    video data across a communication link.

    Image compression is currently a prominent topic for both military and commercial

    researchers. Due to rapid growth of digital media and the subsequent need for reduced

    storage and to transmit the image in an effective manner Image compression is needed.

    Image compression attempts to reduce the number of bits required to digitally represent animage while maintaining its perceived visual quality. This study concentrates on the

    lossless compression of image using approximate matching technique and run lengthencoding. The performance of this method is compared with the available jpeg

    compression technique over a wide number of images, showing good agreements.

    Embedded Zero tree Wavelet (EZW) coding, introduced by J. M. Shapiro, is a veryeffective and computationally simple technique for image compression. Here we offer an

    alternative explanation of the principles of its operation, so that the reasons for its excellent

    performance can be better understood. These principles are partial ordering by magnitude

    with a set partitioning sorting algorithm, ordered bit plane transmission, and exploitation of

    self-similarity across different scales of an image wavelet transform. Moreover, we presenta new and different implementation, based on Set Partitioning in Hierarchical Trees

    (SPIHT), which provides even better performance than our previously reported extensionof the EZW that surpassed the performance of the original EZW. The image coding results,

    calculated from actual file sizes and images reconstructed by the decoding algorithm, are

    either comparable to or surpass previous results obtained through much more sophisticatedand computationally complex methods. In addition, the new coding and decoding

    procedures are extremely fast, and they can be made even faster, with only small loss in

    performance, by omitting entropy coding of the bit stream by arithmetic code.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    4/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 4

    TABLE OF CONTENTS

    Abstract 3

    Table of Contents 4

    List of Figures 5

    1 INTRODUCTION TO IMAGE COMPRESSION PAGE

    NO

    1.1 Introduction1.2 Need for Image Compression1.3 Basic Types of Compression1.4 Flow of Compression1.5 Flow of Encoding

    6781111

    2 COMPESSION TECHNIQUES

    2.1 Lossless Compression Technique.2.2 Lossy Compression Techniques.

    1213-14

    3 RUN LENGTH ENCODING

    3.1 Introduction

    3.2 RLE for image data3.3 Encoding String

    3.4 Decoding String3.5 Variant of Run Length Coding

    3.6 Flow Chart of Run Length Encoding3.7 Matlab Code for Run Length Encoding3.8 Drawbacks of Run Length Encoding 3.9 Application

    of Run Length Encoding

    15

    1619

    2020

    222325

    26

    4. WAVELET TRANSFORM

    4.1 Introduction4.2 Comparison of the signals using Fourier Transform.

    4.3 Adoption of STFT

    2728

    30

    5. PROCESS INVOLVED IN COMPRESSION

    5.1 Image Compression & Decompression Process5.2 BMP file5.3 Wavelet Forward Transform5.4 Thresholding

    5.5 Run Length Encoding and Decoding Techniques.5.6 Inverse Wavelet Transform

    32323538

    3942

    6. DIGITAL SIGNAL PROCESOR

    6.1 Introduction6.2 TMS DSP Processor

    4344

    7. CONCLUSION 48

    8. REFERENCES 49-50

  • 5/26/2018 Run Length Encoding By Surovit Roy

    5/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 5

    LIST OF FIGURES

    Page No

    Figure 1.1 Representation of compression techniques 9

    Figure 1.2 Coding Techniques Tree 10

    Figure 1.3 Flow of Compression 11

    Figure 1.4 Flow of Encoding 12

    Figure 3.1 Simple Encoding and Decoding technique 16

    Figure 3.2 Coding Schemes of Pixels 17

    Figure 3.3 Sequential Processing 18

    Figure 3.4 Line Coding 18

    Figure 3.5 Run Length Variant 21Figure 3.6 Flow Diagram of Run Length Encoding 22

    Figure 3.7 RLE encoding direction 25

    Figure 4.1 Graphical representation of a Stationary signal (equation-1) 27

    Figure 4.2 Graphical representation of a non-stationary signal 28

    Figure 4.3 Graphical representation of Fourier Transformed Stationarysignal

    29

    Figure 4.4 Graphical representation of Fourier Transformed Stationarysignal.

    29

    Figure 5.1 Steps involved in compression technique 32

    Figure 5.2 BMP File format 33Figure 5.3 Types of BMP files 34

    Figure 6.1 Architecture of TMS320C54X DSP Processor 44

  • 5/26/2018 Run Length Encoding By Surovit Roy

    6/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 6

    INTRODUCTION TO IMAGE COMPRESSION

    1.1

    Introduction

    Image compression techniques, especially non-reversible or lossy ones, have beenknown to grow computationally more complex as they grow more efficient, confirming

    the tenets of source coding theorems in information theory that a code for a (stationary)

    source approaches optimality.

    In the limit of infinite computation (source length). Notwithstanding, the image coding

    technique called Embedded Zerotree Wavelet (EZW), introduced by Shapiro, interrupted

    the simultaneous progression of efficiency and complexity. This technique not only was

    competitive in performance with the most complex techniques, but was extremely fast in

    execution and produced an embedded bit stream. With an embedded bit stream, thereception of code bits can be stopped at any point and the image can be decompressed and

    reconstructed. Following that significant work, we developed an alternative exposition ofthe underlying principles of the EZW technique and presented an extension that achieved

    even better results

    In this report, we again explain that the EZW technique is based on three concepts:

    1. Partial ordering of the transformed image elements by magnitude, withtransmission of order by a subset partitioning algorithm that is duplicated at the

    decoder.

    2. Ordered bit plane transmission of refinement bits.

    3. Exploitation of the self-similarity of the image wavelet transform across differentscales. As to be explained, the partial ordering is a result of comparison of transform

    element (coefflcient) magnitudes to a set of octavely decreasing thresholds. We saythat an element is significant or insignificant with respect to a given threshold,

    depending on whether or not it exceeds that threshold.

    In this work, crucial parts of the coding process the way subsets of co-efficient arepartitioned and how the significance information is conveyed are fundamentally different

    from the aforementioned works. In the previous works, arithmetic coding of the bitstreams was essential to compress the ordering information as conveyed by the results ofthe significance tests. Here the subset partitioning is so effective and the significance

    information so compact that even binary uncoded transmission achieves about the same or

    better performance than in these previous works. Moreover, the utilization of arithmeticcoding can reduce the mean squared error or increase the peak signal to noise ratio

    (PSNR) by 0.3 to 0.6 dB for the same rate or compressed file size and achieve results

    which are equal to or superior to any previously reported, regardless of complexity.

    Execution times are also reported to indicate the rapid speed of the encoding and decodingalgorithms. The transmitted code or compressed image file is completely embedded, so

  • 5/26/2018 Run Length Encoding By Surovit Roy

    7/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 7

    that a single file for an image at a given code rate can be truncated at various points anddecoded to give a series of reconstructed images at lower rates. Previous versions [1, 6]

    could not give their best performance with a single embedded file, and required, for each

    rate, the optimization of a certain parameter. The new method solves this problem bychanging the transmission priority, and yields, with one embedded file, its top

    performance for all rates.

    Compression techniques are playing an important role in the world oftelecommunication and multimedia systems where bandwidth is still a valuable

    commodity. Hence, image compression techniques are of prime importance for reducing

    the amount of information needed for the picture without losing much of its quality, judgedby human viewers. The history of compression begins in the 1960s. An analogue

    videophone system had been tried out in the 1960s, but it required a wide bandwidth and

    the postcard-size black-and-white pictures produced did not add appreciably to voice

    communication!

    There are two closely interlinked reasons for compression.

    Firstly, to reduce the size of stored or transmitted files to manageable sizes, or to reduce

    the time it would take to transmit these files to another computer.

    Secondly, to reduce the real-time bandwidth required to transmit time-sensitive videodata across a communication link.

    Communication equipments like modems, bridges, and routers use compressionschemes to improve throughput over standard phone lines or leased lines. Compression is

    also used to compress voice telephone calls transmitted over leased lines so that more calls

    can be placed on those lines. As is the case with any form of communication, compressed

    data communication only works when both the sender and receiver of the informationunderstand the encoding scheme. For example, this text makes sense only if the receiver

    understands that it is intended to be interpreted as characters representing the English

    language. Similarly, compressed data can only be understood if the decoding method isknown by the receiver.8 Text can typically be compressed to approximately 40% of itsoriginal size, and graphics files from 20% to 90%. Some files compress very little. It

    depends entirely on the type of file and compression algorithm used. Some schemes are

    reversible so that the original data can be reconstructed (lossless data compression), whileothers accept some loss of data in order to achieve higher compression (lossy data

    compression).

    1.2 Need for image compression

    An image, 1024 pixel x 1024 pixel x 24 bit, without compression, would require 3MB of storage and 7 minutes for transmission, utilizing a high speed, 64 Kbit/s, ISDN line.

    If the image is compressed at a 10:1 compression ratio, the storage requirement is reduced

    to 300 KB and the transmission time drops to under 6 seconds. Seven 1 MB images can becompressed and transferred to a floppy disk in less time than it takes to send one of the

    original files, uncompressed, over an AppleTalk network. In a distributed environment

    large image files remain a major bottleneck within systems. Compression is an important

  • 5/26/2018 Run Length Encoding By Surovit Roy

    8/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 8

    component of the solutions available for creating file sizes of manageable and transmittabledimensions. Increasing the bandwidth is another method, but the cost sometimes makes this

    a less attractive solution. Platform portability and performance are important in the

    selection of the compression/decompression technique to be employed.

    The best image quality at a given bit-rate (or compression rate) is the main goal of

    image compression, however, there are other important properties of image compressionschemes:

    Scalabilitygenerally refers to a quality reduction achieved by manipulation of the bit

    stream or file (without decompression and re-compression). Other names for scalabilityare progressive coding or embedded bit streams. Despite its contrary nature, scalability also

    may be found in lossless codecs, usually in form of coarse -to-fine pixel scans. Scalability

    is especially useful for previewing images while downloading them (e.g., in a web

    browser) or for providing variable quality access to e.g., databases. There are several typesof scalability:

    Quality progressiveor layer progressive: The bit stream successively refines thereconstructed image.

    Resolution progressive: First encode a lower image resolution; then encode the difference

    to higher resolutions.

    Component progressive: First encode grey; then color.

    Region of interest coding. Certain parts of the image are encoded with higher quality than

    others. This may be combined with scalability (encode these parts first, others later).

    Meta information. Compressed data may contain information about the image which maybe used to categorize, search, or browse images. Such information may include color and

    texture statistics, small preview images, and author or copyright information.

    Processing power. Compression algorithms require different amounts of processingpower to encode and decode. Some high compression algorithms require high processing

    power.

    The quality of a compression method often is measured by the Peak signal-to-noise ratio. It

    measures the amount of noise introduced through a lossy compression of the image,

    however, the subjective judgment of the viewer also is regarded as an important measure,

    perhaps, being the most important measure.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    9/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 9

    1.3 Basic types of compression

    Compression comes in two basic flavors: lossless (or information preserving) andLossy Compression Technique.

    Lossless compression with lossless compression, data is compressed without any loss ofdata. It assumes you want to get everything back that you put in i.e., we can reconstruct a

    perfect reproduction of the original from the compression. Critical financial data files are

    examples where lossless compression is required.

    Lossy compression with lossy compression, it is assumed that some loss of

    Information is acceptable. When you reconstruct the information from the 9 compressed

    data, you get something close to but not exactly the same as the original. You can get more

    compression by allowing the algorithm to lose more information. Lossy compressionalgorithms usually have an adjustable parameter to control this compression vs. quality

    tradeoff. The best example is a videoconference where there is an acceptable amount of

    frame loss in order to deliver the image in real time. People may appear jerky in theirmovements, but you still have a grasp for what is happening on the other end of the

    conference. In the case of graphics files, some resolution may be lost in order to create a

    smaller file. The loss may be in the form of color depth or graphic detail.

    Figure 1.1

    Representation of compression techniques

    Lossy compression can provide compression ratios of 100:1 to 200:1, depending on

    the type of information being compressed. Lossless compression ratios usually only

    achieve a 2:1 compression ratio. Lossy compression techniques are often "tunable" in thatyou can turn the compression up to improve throughput, but at a loss in quality.

    Compression can also be turned downed to the point at which there is little loss of image,

    but throughput will be affected.10 Lossy compression is very useful for images, audio

  • 5/26/2018 Run Length Encoding By Surovit Roy

    10/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 10

    signals, or other information that is perceived through our senses. It is not, however, usefulfor text, numerical data, and use of scanners to locate details in images, etc. where there is

    a precise meaning for the data. Even for images or other perceived signals, lossless

    compression is sometimes required, particularly for legal documents, medical images, etc.

    Imagine the field day a lawyer would have when he finds out that a patient was

    misdiagnosed from a "lossy"- compressed image. It doesn't seem to matter that the lossyversion may be perceptually indistinguishable from the lossless version--the very term"lossy" sends the doctors and lawyers scurrying.

    Some of the data compression techniques:

    Lossless coding techniques

    Run length encoding Huffman encoding Entropy coding (Lempel/Ziv) Area coding

    Lossy coding techniques

    Transform coding (DCT/Wavelets/Gabor) Vector quantization Segmentation and approximation methods Spline approximation methods (Bilinear Interpolation/Regularization) Fractal coding (texture synthesis, iterated functions system [IFS],recursive IFS [RIFS])

    Figure 1.2

  • 5/26/2018 Run Length Encoding By Surovit Roy

    11/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 11

    Coding Techniques Tree

    1.4 Flow of compression

    The image file is converted into a series of binary data, which is called the bit-stream.

    The decoder receives the encoded bit-stream and decodes it to reconstruct theimage.

    ` The total data quantity of the bit-stream is less than the total data quantity of the

    original image.

    Figure 1.3 Flow of Compression

    1.5 The Flow of Encoding

    The flow of encoding an image:

    Reduce the correlation between pixels Quantization- Quantization, involved in image processing, is a lossy

    compression technique achieved by compressing a range of values to a singlequantum value. When the number of discrete symbols in a given stream is reduced,

    the stream becomes more compressible. For example, reducing the number of

    colors required to represent a digital image makes it possible to reduce its file size.

    Specific applications include DCT data quantization in JPEG and DWT dataquantization in JPEG 2000.

    Source Coding- source code is any collection ofcomputer instructions (possiblywithcomments) written using somehuman-readablecomputer language, usuallyastext.The source code of a program is specially designed to facilitate the work of

    computer programmers, who specify the actions to be performed by a computer

    mostly by writing source code. The source code is often transformed byacompilerprogram into low-levelmachine code understood by the computer. The

    machine code might then be stored for execution at a later time. Alternatively,

    Encoder 0101100111... Decoder

    Original Image Decoded ImageBitstream

    http://en.wikipedia.org/wiki/Computer_programhttp://en.wikipedia.org/wiki/Comment_(computer_programming)http://en.wikipedia.org/wiki/Human-readablehttp://en.wikipedia.org/wiki/Computer_languagehttp://en.wikipedia.org/wiki/Plain_texthttp://en.wikipedia.org/wiki/Programmerhttp://en.wikipedia.org/wiki/Compilerhttp://en.wikipedia.org/wiki/Machine_codehttp://en.wikipedia.org/wiki/Execution_(computing)http://en.wikipedia.org/wiki/Execution_(computing)http://en.wikipedia.org/wiki/Machine_codehttp://en.wikipedia.org/wiki/Compilerhttp://en.wikipedia.org/wiki/Programmerhttp://en.wikipedia.org/wiki/Plain_texthttp://en.wikipedia.org/wiki/Computer_languagehttp://en.wikipedia.org/wiki/Human-readablehttp://en.wikipedia.org/wiki/Comment_(computer_programming)http://en.wikipedia.org/wiki/Computer_program
  • 5/26/2018 Run Length Encoding By Surovit Roy

    12/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 12

    aninterpreter can be used to analyze and perform the outcomes of the source codeprogram directlyon the fly.

    Figure 1.4 Flow of encoding

    COMPRESSION TECHNIQUE

    2.1 Lossless data compression

    It is a class of data compression algorithms that allows the original data to be

    perfectly reconstructed from the compressed data. By contrast, lossy data compression,

    permits reconstruction only of an approximation of the original data, though this usuallyallows for improved compression rates (and therefore smaller sized files).

    Lossless data compression is used in many applications. For example, it is used inthe ZIP file format and in the UNIX tool gzips. It is also often used as a component withinlossy data compression technologies (e.g. lossless mid/side joint stereo preprocessing by

    the LAME MP3 encoder and other lossy audio encoders).

    Lossless compression is used in cases where it is important that the original and the

    decompressed data be identical, or where deviations from the original data could be

    deleterious. Typical examples are executable programs, text documents, and source code.Some image file formats, like PNG or GIF, use only lossless compression, while others

    like TIFF and MNG may use either lossless or lossy methods. Lossless audio formats are

    most often used for archiving or production purposes, while smaller lossy audio files are

    typically used on portable players and in other cases where storage space is limited or exactreplication of the audio is unnecessary

    Following techniques are included in lossless compression:

    Huffman Coding: - This is a general technique for coding symbols based on theirstatistical occurrence frequencies (probabilities). The pixels in the image are treated as

    symbols. The symbols that occur more frequently are assigned a smaller number of bits,

    while the symbols that occur less frequently are assigned a relatively larger number of bits.Huffman code is a prefix code. This means that the (binary) code of any symbol is not the

    prefix of the code of any other symbol. Most image coding standards use lossy techniques

    Reduce the

    correlation

    between

    pixels

    Quantization Source

    Coding Bitst

    Original

    Image

    http://en.wikipedia.org/wiki/Interpreter_(computing)http://en.wikipedia.org/wiki/On_the_flyhttp://en.wikipedia.org/wiki/On_the_flyhttp://en.wikipedia.org/wiki/Interpreter_(computing)
  • 5/26/2018 Run Length Encoding By Surovit Roy

    13/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 13

    in the earlier stages of compression and use Huffman coding as the final step.

    Run Length Encoding: -This is a very simple compression method used for sequential

    data. It is very useful in case of repetitive data. This technique replaces sequences ofidentical symbols (pixels), called runs by shorter symbols. The run length code for a gray

    scale image is represented by a sequence {Vi, Ri} where Vi is the intensity of pixel and Ri

    refers to the number of consecutive pixels with the intensity Vi as shown in the figure. If

    both Vi and Ri are represented by one byte, this span of 12 pixels is coded using eight

    bytes yielding a compression ratio of 1: 5.

    LZW Coding: - LZW (Lempel- Ziv Welch) is a dictionary based coding. Dictionary

    based coding can be static or dynamic. In static dictionary coding, dictionary is fixed

    during the encoding and decoding processes. In dynamic dictionary coding, the dictionaryis updated on fly. LZW is widely used in computer industry and is implemented as

    compress command on UNIX.

    Area Coding: -Area coding is an enhanced form of run length coding, reflecting the two

    dimensional character of images. This is a significant advance over the other lossless

    methods. For coding an image it does not make too much sense to interpret it as a

    sequential stream, as it is in fact an array of sequences building up a two dimensionalobject. The algorithms for area coding try to find rectangular regions with the same

    characteristics. These regions are coded in a descriptive form as an element with two points

    and a certain structure. This type of coding can be highly effective but it bears the problemof a nonlinear method, which cannot be implemented in hardware. Therefore, the

    performance in terms of compression time is not competitive, although the compression

    ratio is.

    2.2 Lossy compression technique

    Lossy schemes provide much higher compression ratios than lossless schemes.

    Lossy schemes are widely used since the quality of the reconstructed images is adequate

    for most applications .By this scheme, the decompressed image is not identical to theoriginal image, but reasonably close to it. As shown above the outline of lossy compression

    techniques .In this prediction transformation decomposition process is completely

    reversible .The quantization process results in loss of information. The entropy coding afterthe quantization step, however, is lossless. The decoding is a reverse process. Firstly,

    entropy decoding is applied to compressed data to get the quantized data. Secondly,

    dequantization is applied to it & finally the inverse transformation to get the reconstructedimage.

    Major performance considerations of a lossy compression scheme include:

    1. Compression ratio

    2. Signal - tonoise ratio

    3. Speed of encoding & decoding.

    Lossy compression techniques includes following schemes:

  • 5/26/2018 Run Length Encoding By Surovit Roy

    14/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 14

    1. Transformation coding :- In this coding scheme, transforms such as DFT (Discrete

    Fourier Transform) and DCT (Discrete Cosine Transform) are used to change the pixels in

    the original image into frequency domain coefficients (called transform coefficients).Thesecoefficients have several desirable properties. One is the energy compaction property that

    results in most of the energy of the original data being concentrated in only a few of the

    significant transform coefficients. This is the basis of achieving the compression. Onlythose few significant coefficients are selected and the remaining are discarded. Theselected coefficients are considered for further quantization and entropy encoding.

    2. Vector quantization: - The basic idea in this technique is to develop a dictionary offixed-size vectors, called code vectors. A vector is usually a block of pixel values. A given

    image is then partitioned into non-overlapping blocks (vectors) called image vectors. Then

    for each in the dictionary is determined and its index in the dictionary is used as the

    encoding of the original image vector. Thus, each image is represented by a sequence ofindices that can be further entropy coded

    3. Fractal coding:- The basic idea in this technique is to develop a dictionary of fixed-sizevectors, called code vectors. A vector is usually a block of pixel values. A given image is

    then partitioned into non-overlapping blocks (vectors) called image vectors. Then for each

    in the dictionary is determined and its index in the dictionary is used as the encoding of the

    original image vector. Thus, each image is represented by a sequence of indices that can befurther entropy coded

    4. Block Truncation Coding: -In this scheme, the image is divided into non overlappingblocks of pixels. For each block, threshold and reconstruction values are determined. The

    threshold is usually the mean of the pixel values in the block. Then a bitmap of the block is

    derived by replacing all pixels whose values are greater than or equal (less than) to the

    threshold by a 1 (0). Then for each segment (group of 1s and 0s) in the bitmap, thereconstruction value is determined. This is the average of the values of the corresponding

    pixels in the original block.

    5. Sub band coding: - In this scheme, the image is analyzed to produce the componentscontaining frequencies in well-defined bands, the sub bands. Subsequently, quantization

    and coding is applied to each of the bands. The advantage of this scheme is that the

    quantization and coding well suited for each of the sub bands can be designed separately.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    15/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 15

    RUN LENGTH ENCODING

    3.1 Introduction

    Run-length Encoding, or RLE is a technique used to reduce the size of a repeating

    string of characters. This repeating string is called a run, typically RLE encodes a run of

    symbols into two bytes, a count and a symbol. RLE can compress any type of dataregardless of its information content, but the content of data to be compressed affects the

    compression ratio. Consider a character run of 15 'A' characters which normally would

    require 15 bytes to store:

    AAAAAAAAAAAAAAA is stored as 15A

    With RLE, this would only require two bytes to store, the count (15) is stored as the

    first byte and the symbol (A) as the second byte. In this compression technique, we haveused the approximate matching method in unison with run length.

    Starting from the left uppermost row of image, every three rows are considered at a

    time. Of these, the middle row is represented using run length, and the row above and

    below it are matched with the middle row using approximate matching method. This

    method is continued iteratively until the whole image is scanned and compressed. Run-length encoding (RLE) is a very simple form of data compression in which runs of data

    (that is, sequences in which the same data value occurs in many consecutive data elements)

    are stored as a single data value and count, rather than as the original run. This is mostuseful on data that contains many such runs; for example, simple graphic images such as

    icons and line drawings.

    Example: The string:

    "aaaabbcdeeeeefggggghhhiiiij"

    may be replaced with

    "a4b2c1d1e5f1g5h3i4j1".

    The numbers are in bold to indicate that they are values, not symbols. RLE works

    by reducing the physical size of a repeating string of characters. This repeating string,called a run, is typically encoded into two bytes. The first byte represents the number ofcharacters in the run and is called the run count. In practice, an encoded run may contain 1

    to 128 or 256 characters; the run count usually contains as the number of characters minus

    one (a value in the range of 0 to 127 or 255). The second byte is the value of the characterin the run, which is in the range of 0 to 255, and is called the run value. A black-and-white

    image that is mostly white, such as the page of a book, will encode very well, due to the

    large amount of contiguous data that is all the same color. Make sure that your RLE

    encoder always stops at the end of each scan line of bitmap data that is being encoded.There are several benefits to doing so. Encoding only a simple scan line at a time means

  • 5/26/2018 Run Length Encoding By Surovit Roy

    16/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 16

    that only a minimal buffer size is required. Encoding only a simple line at a time alsoprevents a problem known as cross-coding. Cross-coding is the merging of scan lines that

    occurs when the encoded process loses the distinction between the original scan lines. Ifthe data of the individual scan lines 24 is merged by the RLE algorithm, the point where

    one scan line stopped and another began is lost or, at least, is very hard to detect quickly.

    When an encoder is encoding an image, an end-of-scan-line marker is placed in theencoded data to inform the decoding software that the end of the scan line has been

    reached. This marker is usually a unique packet, explicitly defined in the RLE

    specification, which cannot be confused with any other data packets. End-of-scan-linemarkers are usually only one byte in length, so they don't adversely contribute to the size of

    the encoded data.

    Fig 3.1 Simple Encoding and Decoding technique

    3.2 RLE for Image Data

    Traditionally run length encoding is of importance for the compression of imagedata. The reason is the internal structure of certain images on the one hand and the low

    complexity of the RLE implementation on the other hand.

    Especially technical drawings, sketches and diagrams contain a large proportion ofsingle colored areas, i.e. the data consist of long sequential parts represented by a constant

    value. The RLE coding scheme is totally reversible and does not generate compression

    artefacts, which would particularly affect the mentioned type of contents.

    The relatively small requirements were decisive for the early use of RLE becausethe performance of the workstations was not sufficient for more complex procedures,

    especially for high resolution images.

    To utilize RLE for image data a variety of extensions was introduced to provide

    specific functionalities. Among others, RLE coding schemes were part of certain subformats within the BMP, PCX and TGA specification.

    Encoder 0101100111... Decoder

    Original Image Decoded Im

    Bitstream

  • 5/26/2018 Run Length Encoding By Surovit Roy

    17/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 17

    Pixel Coding

    Conventional RLE procedures base on the standard unit byte. That is well-suited forimage data consisting of 256 colors at maximum. For larger color resolutions the efficiencyof the compression algorithm decreases drastically because longer sequences consisting of

    identical components appear only for gray scaled colors. The components of any other

    color differ within the data structure of a pixel.

    An RGB image with a color resolution of 8 bit does not contain recurring symbols

    on a byte level even for single colored areas. The most simple solution is to collect the

    color components to the basic unit pixel and to assign the counter to repetitions of pixelsinstead of bytes.

    Coding scheme for pixel:

    Fig 3.2 Coding scheme for pixel

    Beyond this simple coding scheme more specialized variants exist, for example the RLE4scheme used for Microsoft Bitmaps consisting of 16 colors.

    Sequential Processing

    A general purpose encoder processes data sequentially in a one-dimensional structure.

    Procedures especially designed for image data could additionally benefit from their two-

    dimensional characteristic. The diagrams below shall demonstrate some possible strategies:

  • 5/26/2018 Run Length Encoding By Surovit Roy

    18/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 18

    Fig 3.3 Sequential Processing

    In practice this processes are not very important for native image data, but equivalent

    technologies are commonly in use. The final entropy coding according to JPEG uses RLE

    to encode the quantified AC coefficients. Therefore a diagonal zig-zag-processing is

    applied. This coefficients do not represent pixels, but frequencies describing the particulararea.

    Line Coding

    A variety of applications process images line by line, even if longer runs would result in abetter compression.

    Originally this procedure was driven by limited capabilities for memory and computing

    power. The resources for a temporary buffer will be saved without the need for decoding.

    The run-time performance increases accordingly.

    Moreover the limitation on line boundaries prevents from incompatibilities because several

    applications and formats take this for granted.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    19/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 19

    Even if this is no longer necessary looking to the performance of current systems, this

    procedure is adapted to other data types requiring more resources (like the frame coding for

    video data).

    Fig 3.4 Line coding

    Cross-Coding

    The incorrect assignment of the contents to particular lines is denoted as cross-coding in

    several publications. The most important reason shall be runs exceeding the end of lines,

    which will be decoded mistakenly.

    Limiting the encoding process to single lines will avoid this problem in any case and for

    any type of decoder.

    End of Line Marker

    Image data are commonly structured line by line, i.e. for any processing the first line of aparticular area has to be accessed. During run length encoding the correlation between

    coordinates and the corresponding position within a file is lost.

    Several data formats provide a special marker that allows to identify the end or the

    beginning of a line even within already encoded data. This end of line marker is uniquely

    defined outside the common range of values. It can be detected by reading the data stream

    without decoding.

    Repetition of Lines

    The general principle to replace identical pixels by the number of repetitions, could be

    transformed to a line-level. Especially sketches and technical drawings consist of contents

    that would profit from this functionality.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    20/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 20

    Such a line repetition could be initiated by a dedicated marker, but it would reduce the

    range of values for the remaining contents. It is not well-known whether this is used in

    common formats.

    Lossy RLE

    The attribute "lossy" is a contradiction to the fundamental mechanisms of the RLE.

    However procedures for special applications were developed, which reduce the color

    resolution while encoding. The losses result from the entire encoding scheme, not from runlength encoding itself.

    The aim of this procedures was a better compression for image data like pictures or photos.

    Whether this technology was used to a larger extent, is not well-known. In the meantimesuch methods become obsolete because more complex algorithms offer better compression

    rates and quality.

    3.3 Encoding Strings

    Encoding using RLE is fairly simple. The following process can be implemented to attainencoding:

    Step 1. Set the previous symbol equal to an unmatchable value.

    Step 2. Read the next symbol from the input stream.

    Step 3. If the symbol is an EOF exit.

    Step 4. Write out the current symbol.

    Step 5. If the symbol is an does not match the previous symbol, set the previous

    symbol to the current symbol, and go to step 2.

    Step 6. Read and count additional symbols until a non-matching symbol is found.

    This is the run length.

    Step 7. Write out the run length.

    Step 8. Write out the non-matching symbol.

    Step 9. Set the previous symbol to the non-matching symbol, and go to step 2.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    21/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 21

    3.4 Decoding strings

    Decoding is even easier than encoding. Not only are there less steps, but there are no

    caveats. To decode an encoded stream the following steps are followed:

    Step 1. Set the previous symbol equal to an unmatchable value.

    Step 2. Read the next symbol from the input stream.

    Step 3. If the symbol is an EOF exit.

    Step 4. Write out the current symbol.

    Step 5. If the symbol is an does not match the previous symbol, set the previous

    symbol to the current symbol, and go to step 2.

    Step 6. Read the run length.

    Step 7. Write out the current symbol for the amount indicated by the run length.

    Step 8. Go to step 1.

    3.5 Variants of Run Length Coding

    There are a number of variants of run-length encoding. Image data is normally run-lengthencoded in a sequential process that treats the image data as a 1D stream, rather than as a

    2D map of data. In sequential processing, a bitmap is encoded starting at the upper leftcorner and proceeding from left to right across each scan line (the X axis) to the bottom

    right corner of the bitmap. But alternative RLE schemes can also be written to encode data

    down the length of a bitmap (the Y axis) along the columns to encode a bitmap into 2Dtiles, or even to encode pixels on a diagonal in a zig-zag fashion. Odd RLE variants such as

    this last one might be used in highly specialized applications but are usually quite rare.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    22/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 22

    Fig.3.5 Run Length Variant

    Another seldom-encountered RLE variant is a lossy run-length encoding algorithm.RLE algorithms are normally lossless in their operation. However, discarding data during

    the encoding process, usually by zeroing out one or two least significant bits in each pixel,

    can increase compression ratios without adversely affecting the appearance of very

    complex images. This RLE variant works well only with real-world images that containmany subtle variations in pixel values.

    Make sure that your RLE encoder always stops at the end of each scan line of

    bitmap data that is being encoded. There are several benefits to doing so. Encoding only a

    simple scan line at a time means that only a minimal buffer size is required. Encoding onlya simple line at a time also prevents a problem known as cross-coding.

    Cross-coding is the merging of scan lines that occurs when the encoded process

    loses the distinction between the original scan lines. If the data of the individual scan lines

    is merged by the RLE algorithm, the point where one scan line stopped and another beganis lost or, at least, is very hard to detect quickly.

    Cross-coding is sometimes done, although we advise against it. It may buy a few

    extra bytes of data compression, but it complicates the decoding process, adding time cost.For bitmap file formats, this technique defeats the purpose of organizing a bitmap image by

    scan lines in the first place. Although many file format specifications explicitly state thatscan lines should be individually encoded, many applications encode image data as acontinuous stream, ignoring scan-line boundaries.

    Have you ever encountered an RLE-encoded image file that could be displayed

    using one application but not using another? Cross-coding is often the reason. To be safe,

    decoding and display applications must take cross-coding into account and not assume thatan encoded run will always stop at the end of a scan line.

    When an encoder is encoding an image, an end-of-scan-line marker is placed in the

    encoded data to inform the decoding software that the end of the scan line has beenreached. This marker is usually a unique packet, explicitly defined in the RLE

  • 5/26/2018 Run Length Encoding By Surovit Roy

    23/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 23

    specification, which cannot be confused with any other data packets. End-of-scan-linemarkers are usually only one byte in length, so they don't adversely contribute to the size of

    the encoded data.

    Encoding scan lines individually has advantages when an application needs to use

    only part of an image. Let's say that an image contains 512 scan lines, and we need to

    display only lines 100 to 110. If we did not know where the scan lines started and ended inthe encoded image data, our application would have to decode lines 1 through 100 of theimage before finding the ten lines it needed. Of course, if the transitions between scan lines

    were marked with some sort of easily recognizable delimiting marker, the application could

    simply read through the encoded data, counting markers until it came to the lines it needed.But this approach would be a rather inefficient one.

    3.6 Basic Run Length Encoding Flow

    Fig 3.6 Flow Diagram of Run Length Encoding

  • 5/26/2018 Run Length Encoding By Surovit Roy

    24/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 24

    The parts of run-length encoding algorithms that differ are the decisions that are

    made based on the type of data being decoded (such as the length of data runs). RLE

    schemes used to encode bitmap graphics are usually divided into classes by the type ofatomic (that is, most fundamental) elements that they encode. The three classes used by

    most graphics file formats are bit-, byte-, and pixel-level RLE.

    Bit-level RLEschemes encode runs of multiple bits in a scan line and ignore byte and wordboundaries. Only monochrome (black and white), 1-bit images contain a sufficient numberof bit runs to make this class of RLE encoding efficient. A typical bit-level RLE scheme

    encodes runs of one to 128 bits in length in a single-byte packet. The seven least significant

    bits contain the run count minus one, and the most significant bit contains the value of thebit run, either 0 or 1. A run longer than 128 pixels is split across several RLE-encoded

    packets.

    Byte-level RLE schemes encode runs of identical byte values, ignoring individualbits and word boundaries within a scan line. The most common byte-level RLE scheme

    encodes runs of bytes into 2-byte packets. The first byte contains the run count of 0 to 255,

    and the second byte contains the value of the byte run. It is also common to supplement the2-byte encoding scheme with the ability to store literal, unencoded runs of bytes within the

    encoded data stream as well.

    In such a scheme, the seven least significant bits of the first byte hold the run count minus

    one, and the most significant bit of the first byte is the indicator of the type of run thatfollows the run count byte. If the most significant bit is set to 1, it denotes an encoded run.

    Encoded runs are decoded by reading the run value and repeating it the number of times

    indicated by the run count. If the most significant bit is set to 0, a literal run is indicated,meaning that the next run count bytes are read literally from the encoded image data. The

    run count byte then holds a value in the range of 0 to 127 (the run count minus one). Byte-

    level RLE schemes are good for image data that is stored as one byte per pixel.

    Pixel-level RLE schemes are used when two or more consecutive bytes of image

    data are used to store single pixel values. At the pixel level, bits are ignored, and bytes are

    counted only to identify each pixel value. Encoded packet sizes vary depending upon thesize of the pixel values being encoded. The number of bits or bytes per pixel is stored in theimage file header. A run of image data stored as 3-byte pixel values encodes to a 4-byte

    packet, with one run-count byte followed by three run-value bytes. The encoding method

    remains the same as with the byte-oriented RLE.

    When decoding, a character is read; if the character is a flag value, the run count

    and run values are read, expanded, and the resulting run written to the data stream. If the

    character read is not a flag value, it is written directly to the uncompressed data stream.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    25/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 25

    Matlab codes used in Run Length Encoding:-

    Imread = Read image from graphics fileSyntax: A = imread(filename, fmt)

    A = imread(filename, fmt) reads a grayscale or color image from the

    file specified by the string filename. If the file is not in

    the current folder, or in a folder on the MATLAB path, specifythe full pathname.

    Imshow = Display ImageSyntax: imshow(i)

    imshow displays the image I in a Handle Graphics

    figure, where I is agrayscale, RGB (true color), or binary image. For binary

    images, displays pixels with the value 0 (zero) as black and 1 as

    white.

    Graythresh= % Compute global image threshold using Otsu's method.Syntax= graythresh (I)

    Double = Conversion to double precisionIn Matlab, this function returns a Boolean type value for a Booleaninput whereas Scilab function returns a Double type value.

    Length = Length of vector or largest array dimensionnumberOfElements = length(array)

    length(array) finds the number of elements along the largestdimension of an array. Array is an array of any MATLAB

    data type

    and any valid dimensions. numberOfElements is a whole number of

    the MATLAB double class.

    Display = Display text and numeric expressions.Syntax: display(X)

    display(X)prints the value of X. MATLABimplicitly calls

    display after any variable or expression that is not terminated by asemicolon.

    To customize the display of objects, overload the disp function

    instead of the display function. Display calls disp.

    http://www.mathworks.in/help/matlab/ref/display.html?searchHighlight=display#inputarg_Xhttp://www.mathworks.in/help/matlab/ref/display.html?searchHighlight=display#inputarg_X
  • 5/26/2018 Run Length Encoding By Surovit Roy

    26/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 26

    3.7 Drawbacks of Run Length Encoding

    There are two potential drawbacksto this method:

    The minimum useful run-length size is increased from three characters to four. Thiscould affect compression efficiency with some types of data.

    If the unencoded data stream contains a character value equal to the flag value, itmust be compressed into a 3-byte encoded packet as a run length of one. This

    prevents erroneous flag values from occurring in the compressed data stream. If

    many of these flag value characters are present, poor compression will result. The

    RLE algorithm must therefore use a flag value that rarely occurs in theuncompressed data stream.

    Fig 3.7 RLE encoding direction

    3.9 Application of Run Length Encoding

    Run-length encoding (RLE) is a very simple form of data compression in

    which runs of data (that is, sequences in which the same data value occurs in many

    consecutive data elements) are stored as a single data value and count, rather than as theoriginal run. This is most useful on data that contains many such runs: for example,

    relatively simple graphic images such as icons, line drawings, and animations. It is not

    useful with files that don't have many runs as it could potentially double the file size.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    27/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 27

    Application of Run Length Encoding:-

    Run-length encoding performs lossless data compression and is well suitedto palette-based iconic images. It does not work well at all on continuous-tone

    images such as photographs, although JPEG uses it quite effectively on the

    coefficients that remain after transforming and quantizing image blocks.

    Common formats for run-length encoded data include True vision, PackBits, PCX and ILBM.

    Run-length encoding is used in fax machines (combined with other techniquesinto Modified Huffman coding). It is relatively efficient because most faxed

    documents are mostly white space, with occasional interruptions of black.

    Data that have long sequential runs of bytes (such as lower-quality sound samples)can be RLE compressed after applying a predictive filter such as delta encoding.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    28/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 28

    WAVELET TRANSFORM

    4.1 Introduction

    The reason why we choose wavelet transform goes way down to other

    transforms like Fourier and short time Fourier transforms. So let us have a brief look

    of both these transforms starting with fourier transform:

    We generally have two types of signals.

    Stationary signals Non-stationary signals

    Stationary signals:

    Signals whose frequency content do not change in time are calledstationary signals. In this case, one does not need to know at what times

    frequency components exist , since all frequency components exist at all times.

    For example the followingsignal:

    x(t)=cos(2*pi*10*t)+cos(2*pi*25*t)+cos(2*pi*50*t)+cos(2*pi*1

    00*t)

    Equation -1

    is a stationary signal, because it has frequencies of 10, 25, 50, and 100 Hz

    at any given time instant. This signal is plotted below:

    Figure 4.1 Graphical representation of a Stationary signal (equation-1

  • 5/26/2018 Run Length Encoding By Surovit Roy

    29/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 29

    Non Stationary signal:

    A signal with different frequency components at different time intervals, hence a non-

    stationary signal .The frequency content of non-stationary signals change in time. In

    this case one should know what frequency components occur at what times.

    Figure 4.2 Graphical representation of a non-stationary signal

    4.2. Comparison of the signals using Fourier Transform

    The top plot in Figure 4.3 is the (half of the symmetric) frequency spectrum of

    the signal in Figure 4.1. The bottom plot is the zoomed version of the top plot,showing only the range of frequencies that are of interest to us. Note the four spectral

    components corresponding to the frequencies 10, 25, 50 and 100 Hz.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    30/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 30

    Fourier transform of the stationary signal:

    Figure 4.3 Graphical representation of Fourier Transformed stationary signal

    Fourier transform of non-stationary signal:

    Figure 4.4 Graphical representation of Fourier transformed non-stationary signal

  • 5/26/2018 Run Length Encoding By Surovit Roy

    31/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 31

    Now, compare the Figures 4.3 and 4.4. The similarity between these two

    spectrums should be apparent. Both of them show four spectral components at exactly

    the same frequencies, i.e., at 10, 25, 50, and 100 Hz. Other than the ripples, and the

    difference in amplitude (which can always be normalized), the two spectrums arealmost identical, although the corresponding time-domain signals are not even close to

    each other. Both of the signals involves the same frequency components, but the first

    one has these frequencies at all times, the second one has these frequencies at differen tintervals. So, how come the spectrums of two entirely different signals look very

    much alike? Recall that the FT gives the spectral content of the signal, but it gives no

    information regarding where in time those spectral components appear. Therefore, FT is

    not a suitable technique for non-stationary signal.

    4.3. Adoption of STFT

    To overcome this we adopt SHORT TIME FOUTIER TRANSFORM (STFT),which is the modified version of Fourier transform. In STFT, the non-stationary signal is

    divided into small portions, which are assumed to be stationary. This is done using a

    window function of a chosen width (i.e., fixed), which is shifted and multiplied withthe signal to obtain the Short Time Fourier Transform of the signal.

    The problem with STFT goes back to Heisenberg uncertainty principle whichstates that it is impossible for one to obtain which frequencies exist at which timeinstance, but one can obtain the frequency bands existing in a time interval. This gives

    rise to resolution issue where there is tradeoff between the time resolution and frequency

    resolution. To assume stationary the window is supposed to be narrow, which results

    in a poor frequency resolution, i.e., it is difficult to know the exact frequencycomponents that exist in the signal; only the band of frequencies that exist is obtained. If

    the width of the window is increased, frequency resolution improves but time resolution

    becomes poor, i.e., it is difficult to know what frequencies occur at which timeintervals. Also, c h o o s i n g a w i d e window may violate the condition of

    stationary.

    The Wavelet Transform solves the above problem to a certain extent. In contrast

    to STFT, which uses a single analysis window, the wavelet transform uses short

    windows at high frequencies and long windows at low frequencies. This results inmulti resolution analysis by which the signal is analyzed with different resolutions at

    different frequencies, i.e., both frequency resolution and time resolution vary in the

    time frequency plane without violating the Heisenberg inequality.

    Therefore, the wavelet transform can be defined as a mathematical tool

    that decomposes a signal into a representation that shows signal details and trends as

    a function of time. This representation can be used to characterize transient events,reduce noise, compress data, and perform many other operations. The main

    advantages of wavelet methods over traditional Fourier methods are the use of

    localized basis functions and the faster computation speed. Localized basis functionsare ideal for analyzing real physical situations in which a signal contains

    discontinuities and sharp spikes

  • 5/26/2018 Run Length Encoding By Surovit Roy

    32/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 32

    PROCESS INVOLVED IN COMPRESSION

    5.1. Image Compression and Decompression Process

    The basic block diagram showing the steps involved in the process of image

    compression and de-compression.

    WAVELET FORWARD TRANSFORM

    BMP

    FILEEXTRACT

    HEADER &

    PIXEL INFO.

    ROW

    FORWARD

    COLUMN

    FORWARD

    COLUMN

    FORWAR

    D

    THRESHOLD

    WAVELET INVERSE TRANSFORM

    INVERSE

    ROWFORWARD

    INVERSE

    COLUMNFORWARD DECODING

    RUN-

    LENGTHENCODING

    Figure 5.1 Steps involved in Compression Technique.

    5.2 BMP File

    A BMP file consists of two parts mainly.

    1. HEADER consists of information about the image and is same for all theimages of its type.

    2. PIXEL is the content of the image and it varies depending upon the type and content of the

    image file.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    33/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 33

    Color Image:

    It consists of 54 bytes of header information. One pixel occupies 3 bytememory space in which Red, Green and Blue occupies 1 byte each.

    Grey Scale Image:

    An optical pattern consisting of discrete steps or shades of gray between

    black and white is known as grey scale image.It consists of 1078 bytes ofheader information. In this type of image one pixel occupies one byte memory

    and its values range from 0 to

    255. 0 represents black and 255 representswhite.

    Black & White Image:

    It consists of 1078 bytes of header information. This type of image also

    occupies one byte memory for every pixel. 0 represents black and 1 representswhite.

    Extraction:

    This process includes the extraction of header information and pixel

    information from the input image file. Pixel information varies from image toimage those results in the process where as the header information remains the

    same.

    5.3 Wavelet Forward Transform

    It is a mathematical tool that decomposes a signal into a representation that

    shows signal details and trends as a function of time. The wavelet

    transform or wavelet analysis is probably the most recent solution toovercome shortcomings of fourier transform. In this type of transform asfrequency increases the time resolution increases; likewise as frequency

    decreases the frequency resolution increases. Thus a certain high frequency

    component can be located more accurately in time than a low frequency

    component and a low frequency component can be located more accurately infrequency compared to a high frequency component.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    34/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 34

    Types of wavelet algorithms:

    There are a wide variety of popular wavelet algorithms. Some of

    them are

    Haar Wavelets

    Daubechies Wavelets

    Mexican Hat Wavelets

    Morlet Wavelets

    Why Haar Wavelets?

    Of these algorithms, including Daubechies wavelets, Mexican Hat wavelets

    and Morlet wavelets have the advantage of better resolution for smoothlychanging time series. But they have the disadvantage of being more expensive

    to calculate than the Haar wavelets. The higher resolution provided by these

    wavelets is not worth the cost for financial time series (non-stationary), whichare characterized by jagged transitions.

    Haar Wavelets:

    The Haar wavelet algorithms are applied to time series

    1

    where the number ofsamples is a power of two (e.g., 2, 4, 8, 16, 32, 64...) The Haar wavelet

    uses a rectangular window to sample the time series. The first pass over the

    time series uses a window width of two. The window width is doubled ateach step until the window encompasses the entire time series.

    Each pass over the time series generates a new time series and a set of

    coefficients. The new time series is the average of the previous time seriesover the sampling window. The coefficients represent the average change inthe sample window. For A time series is simply a sample of a signal or

    a record of something, like temperature, water level or market data (like

    equity close price).Example, if we have a time series consisting of the samplessi,si+1,si+2... then the Haar wavelet equations is

  • 5/26/2018 Run Length Encoding By Surovit Roy

    35/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 35

    where ci is the wavelet

    coefficient.

    The Haar transform preserves the average in the smoothed values (this is not

    true of all wavelet transforms). The scaling function produces a smoother

    version of the data set, which is half the size of the input data set. Waveletalgorithms are recursive and the smoothed data becomes the input for the next

    step of the wavelet transform. The

    Haar wavelet scaling function

    is

    where ai is a smoothed value.

    Function of various Filters in Wavelet Transform: High pass filter

    In digital signal processing (DSP) terms, the wavelet function is a high passfilter. A high pass filter allows the high frequency components of a signal

    through while suppressing the low frequency components. For example, the

    differences that are captured by the Haar wavelet function represent highfrequency change between an odd and an even value.

    Low pass filter

    In digital signal processing (DSP) terms, the scaling function is a low passfilter. A low pass filter suppresses the high frequency components of a signal

    and allows the low frequency components through. The Haar scaling function

    calculates the average of an even and an odd element, which results in asmoother, low pass signal. In the wavelet literature this tree structured

    recursive algorithm is referred to as a pyramidal algorithm.

    Wavelets allow a time series to be viewed in multiple resolutions. Eachresolution reflects a different frequency. The wavelet technique takes averages

    and differences of a signal, breaking the signal down into spectrum. All the

    wavelet algorithms work on time series a power of two values (e.g., 64, 128,

    256...). Each step of the wavelet transform produces two sets of values: a set ofaverages and a set of differences (the differences are referred to as wavelet

    coefficients). Each step produces a set of averages and coefficients that is

    half the size of the input data. For example, if the time series contains 256

    elements, the first step will produce 128 averages and 128 coefficients. Theaverages then become the input for the next step (e.g., 128 averages resulting in

    a new set of 64 averages and 64 coefficients). This continues until one

    average and one coefficient (e.g., 20) is calculated.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    36/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 36

    The average and difference of the time series is made across a window of

    values. Most wavelet algorithms calculate each new average and difference byshifting this window over the input data. For example, if the input time series

    contains 256 values, the window will be shifted by two elements, 128 times, in

    calculating the averages and differences. The next step of the calculation uses

    the previous set of averages, also shifting the window by two elements. This

    has the effect of averaging across a four element window. Logically, the windowincreases by a factor of two each time.

    The Haar wavelet transform has a number of

    advantages:

    It is conceptually simple.

    It is fast.

    It is memory efficient, since it can be calculated in place without atemporary array.

    It is exactly reversible without the edge effects that are a problem withother wavelet transforms.

    Works better (comparatively) for financial time series applications.

    5.4 Thresholding

    In certain signals, many of the wavelet coefficients are close or equal to zero.Through a method called thresholding, these coefficients may be modified so

    that the sequence of wavelet coefficients contains long strings of zeroes.

    Through a type of compression known as entropy coding, these long strings maybe stored and sent electronically in much less space. There are different types of

    thresholding.

    Hard thresholding

    Soft thresholding

    Quantile thresholding

    Hard Thresholding:

    In hard thresholding, a tolerance is selected. Any wavelet whose absolute value

    falls below the tolerance is set to zero with the goal to introduce many zeros

    without losing a great amount of detail. There is not a straight forwardeasy way to choose the threshold, although the larger the threshold that is

    chosen the more error that is introduced into the process.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    37/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 37

    Soft Thresholding:

    This is another type of thresholding known as soft thresholding. Once

    again a tolerance, h, is selected. If the absolute value of an entry is less than

    the tolerance, than that entry is set to zero. All other entries, d, are replaced

    with sign(d)||d| - h|. Soft thresholding can be thought of as a translation of

    the signal toward zero by the amount h.

    Quantile Thresholding:

    A third type of thresholding is quantile thresholding. In this method a

    percentage p of entries to be eliminated are selected. The smallest (inabsolute value) p percent of entries are set to zero.

    We generally use hard thresholding in order to obtain high output efficiencywithout much loss and altering of data.

    5.5 Run Length Encoding and Decoding Techniques

    Run-length encoding (RLE) is a very simple form of data compression inwhich runs of data (that is, sequences in which the same data value occurs in

    many consecutive data elements) are stored as a single data value and count,

    rather than as the original run. This is most useful on data that contains many

    such runs; for example, simple graphic images such as icons and line drawings.

    Example:

    The string: "aaaabbcdeeeeefggggghhhiiiij"may be replaced with

    "a4b2c1d1e5f1g5h3i4j1".

    The numbers are in bold to indicate that they are values, not symbols.RLEworks by reducing the physical size of a repeating string of characters. This

    repeating string, called a run, is typically encoded into two bytes. The first

    byte represents the number of characters in the run and is called the run count.

    In practice, an encoded run may contain 1 to 128 or 256 characters; the runcount usually contains as the number of characters minus one (a value in the

    range of 0 to 127 or 255). The second byte is the value of the character in the

    run, which is in the range of 0 to 255, and is called the run value. A black-and-white image that is mostly white, such as the page of a book, will encode very

    well, due to the large amount of contiguous data that is all the same color. Make

    sure that your RLE encoder always stops at the end of each scan line of bitmapdata that is being encoded. There are several benefits to doing so. Encoding

    only a simple scan line at a time means that only a minimal buffer size is

  • 5/26/2018 Run Length Encoding By Surovit Roy

    38/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 38

    required. Encoding only a simple line at a time also prevents a problem known

    as cross-coding.

    Cross-coding is the merging of scan lines that occurs when the encoded

    process loses the distinction between the original scan lines. If the data of theindividual scan line is merged by the RLE algorithm, the point where one

    scan line stopped and another began is lost or, at least, is very hard to detectquickly.

    When an encoder is encoding an image, an end-of-scan-line marker is placed inthe encoded data to inform the decoding software that the end of the scan line

    has been reached. This marker is usually a unique packet, explicitly defined in

    the RLE specification, which cannot be confused with any other data packets.

    End-of-scan-line markers are usually only one byte in length, so they don'tadversely contribute to the size of the encoded data.

    5.6 Inverse Wavelet Transform

    The forward wavelet transform is an invertible mapping; in fact and this

    process is the inverse mapping of the forward wavelet transform. Let us

    consider ci, ci+1, .. as wavelet coefficients and ai, ai+1, . as wavelet

    averages or smoothed values, then the required original data si, si+1, can be

    obtained by the following inverse wavelet equations.

    si = ai + ci

    si+1 = ai - ci

    The obtained output data constitutes to the final decompressed image.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    39/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 39

    DIGITAL SIGNAL PROCESSOR

    6.1 Introduction

    A signal is any variable that carries information. Examples of the types ofsignals of interest are

    Speech (telephony, radio, everyday communication). Biomedical signals (EEG brain signals). Sound and music. Video and image. Radar signals (range and bearing).Digital signal processing (DSP) is concerned with the digital representation of signals and

    the use of digital processors to analyze, modify, or extract information from

    signals. Many signals in DSP are derived from analogue signals which have beensampled at regular intervals and converted into digital form.

    The key advantages of DSP over analogue processing are

    o Guaranteed accuracy (determined by the number of bits used).o Perfect reproducibility.o No drift in performance due to temperature or age.o Takes advantage of advances in semiconductor technology.o Greater flexibility (can be reprogrammed without modifying hardware).

    Superior performance (linear phase response possible, and filtering algorithms can bemade adaptive).Sometimes information may already be in digital form. There are

    however some disadvantages. Speed and cost (DSP design and hardware may be

    expensive, especially with high bandwidth signals). Finite word length problems (limitednumber of bits may cause degradation).

    6.2 TMS320VC5416 DSP Processor

    Description:

    The TMS320VC5416 fixed-point, digital signal processor (DSP) (hereafter referred

    to as the 5416 unless otherwise specified) is based on an advanced modified Harvard

    architecture that has one program memory bus and three data memory buses. Thisprocessor provides an arithmetic logic unit (ALU) with a high degree of parallelism,

    application-specific hardware logic, on-chip memory, and additional on-chip

    peripherals. The basis of the operational flexibility and speed of this DSP is a highly

    specialized instruction set. Separate program and data spaces allow simultaneous

  • 5/26/2018 Run Length Encoding By Surovit Roy

    40/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 40

    access to program instructions and data, providing a high degree of parallelism. Two

    read operations and one write operation can be performed in a single cycle.Instructions with parallel store and application-specific instructions can fully utilize

    this architecture. In addition, data can be transferred between data and program

    spaces. Such parallelism supports a powerful set of arithmetic, logic, and bit-

    manipulation operations that can all be performed in a single machine cycle. The 5416

    also includes the control mechanisms to manage interrupts, repeated operations, andfunction calls. Enhanced Harvard architecture built around one program bus, three

    data buses, and four address buses for increased performance and versatility. AdvancedCPU design with a high degree of parallelism and application specific hardware

    logic for increased performance. A highly specialized instruction set for faster

    algorithms and for optimized high-level language operation. Modulararchitecture design for fast development of spinoff devices. Advanced IC processing

    technology for increased performance and low power consumption. Low power

    consumption and increased radiation hardness because of new static design

    techniques. These are some of the major advantages offered by C5416.

    Architecture and Specifications:

    Fig.6.1 Architecture of TMS320C54X DSP Processor

  • 5/26/2018 Run Length Encoding By Surovit Roy

    41/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 41

    It comprises the central processing unit (CPU), memory and on-chipperipherals. The 54x DSP`s use an advanced modified Harvard

    architecture that maximizes processing power w i t h e i g h t buses.

    Separate program and d a t a s p a c e s allow simultaneous access to

    program instructions and data, providing a high degree of parallelism. For

    example, 3 reads and 1 write can be performed in a single cyc le. Instructionswith parallel store and application-specific instructions fully utilize this

    architecture. In addition, data can be transferred between data and programspaces. Such parallelism supports a powerful set of arithmetic, logic and bit-

    manipulation operations that can all be performed in a single machine cycle.

    Also, the 54x includes the control mechanisms to manage interrupts,repeated operations, and function calling.

    CPU:

    Advanced multi-bus architecture with one program bus, three data

    buses and four address buses 40-bit arithmetic logic unit (ALU), including a 40-bit barrel shifter

    and two independent 40-bit accumulators

    17-bit x 17-bit parallel multiplier coupled to a 40-bit dedicatedadder for non-pipelined single-cycle multiply/accumulate (MAC)

    operation

    Exponent encoder to compute the exponent of a 40-bit accumulatorvalue in a single cycle

    Two address generators, including eight auxiliary registers andtwo auxiliary registers arithmetic units

    Memory:

    192K words x 16-bit addressable memory space (64K- words program,

    64K- words data and 64K-words I/O), with extended program memory.

    It has got high speed on chip memory.

    Buses:

    The 54x architecture is built around eight major 16-bit buses (four

    program/data buses and four address buses):

    The program bus (PB) carries the instruction code and immediateoperands from program memory.

    Three data buses (CB, DB and EB) interconnect to various elements,such as the CPU, data address generation logic, program address

    generation, and on- chip peripherals and data memory.

    TheCB and DB carry the operands that are read from data memory.

    TheEB carries the data to be written to memory.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    42/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 42

    Four address buses (PAB, CAB, DAB and EAB) carry the addressesneeded for instruction execution.

    Addressing Modes:

    The 54x offers seven basic data addressing

    modes:

    Immediate addressing uses the instruction to encode a fixed value

    Absolute addressing uses the instruction to encode a fixed address

    Accumulator addressing uses accumulator A to access a location in

    program memory as data

    Direct addressing uses seven bits of the instruction to encode thelower seven bits of an address. The seven bits are used with the data

    page pointer (DP) or the stack pointer (SP) to determine the actual

    memory address

    Indirect addressing uses the auxiliary registers to accessmemory

    Memory-mapped registers addressing uses the memory-mapped

    registers without modifying either the current DP value or the

    current SP value

    Stack addressing manages adding and removing items from the systemstack during the execution of instructions using direct, indirect or

    memory-mapped register addressing, the data-address generation logic(DAGEN) computes the addresses of data-memory operands.

    Instruction Set:

    Single-instruction repeat and block repeat operations

    Block memory move instructions for better program anddata management

    Instructions with a 32-bit long operand

    Instructions with 2- or 3-operand simultaneous reads

    Arithmetic instructions with parallel store and parallel load

    Conditional-store instructions

  • 5/26/2018 Run Length Encoding By Surovit Roy

    43/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 43

    On-Chip Peripherals:

    Software-programmable wait-state generator

    Programmable bank switching

    External bus-off control to disable the external data bus, address

    bus and control signals.

    Data bus with a bus holder feature

    Speed:

    25/20/15/12.5/10-ns execution time for a single-cycle,

    fixed-point instruction

    Features:

    Advanced multi bus architecture with three separate 16- bit data memory

    buses and one program memory bus.

    40-bit arithmetic logic unit (ALU) including a 40- bit barrel shifter andtwo independent 40- bit accumulators.

    Two address generators with eight auxiliary registers and two auxiliaryregisters arithmetic units (ARAUS).

    Data bus with a bus holder feature.

    Application areas of DSP are considerable:

    Image processing (pattern recognition, robotic vision, imageenhancement, facsimile, satellite weather map, animation).

    Instrumentation and control (spectrum analysis, position and ratecontrol, noise reduction, data compression).

    Speech and audio (speech recognition, speech synthesis, text to speech,digital audio, equalization).

    Military (secure communication, radar processing, sonar processing,and missile guidance).

    Telecommunications (echo cancellation, adaptive equalizations,spread spectrum, video conferencing, and data

    communication). Biomedical (patient monitoring, scanners, EEG brain mappers, ECG

    analysis, X-ray storage and enhancement).

  • 5/26/2018 Run Length Encoding By Surovit Roy

    44/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 44

    CONCLUSION

    Compression is the process of reducing the number of bits or bytes needed torepresent a given set of data. Compression takes advantage of redundancies or

    similarities in the data file. By reducing the number of bits or bytes used to store a set ofdata, we not only reduce the space required to store it, we also reduce thebandwidth needed to transmit it.

    Compression does have its trade-offs. The more efficient the compression technique,the more complicated the algorithm will be and thus, requires more computational

    resources or more time to decompress. This tends to affect the speed. Speed is not so

    much of an importance to still images but weighs a lot in motion-pictures.

    The same process of compression technique can be applied to color images by

    making necessary changes in the program. Here, we achieved a suitable compression ratio

    for the binary image. But in practice, such a large compression ratios cannot be obtainedfor audio, video or any other multimedia files.

    There are two potential drawbacksto this method:

    The minimum useful run-length size is increased from three characters to four. This couldaffect compression efficiency with some types of data.

    If the unencoded data stream contains a character value equal to the flag value, it must be

    compressed into a 3-byte encoded packet as a run length of one. This prevents erroneousflag values from occurring in the compressed data stream. If many of these flag value

    characters are present, poor compression will result. The RLE algorithm must therefore use

    a flag value that rarely occurs in the uncompressed data stream.

    We were able to successfully implement the RLE on our DSP. The RLE algorithm is a

    simple one; however, its implementation on the DSP is not as simple. Our MATLAB

    implementation was fairly simple to write and run. Writing the DSP assembly code was farmore complex. The DSP assembly code requires us to be much more precise and

    deliberate.

    Future improvements to our RLE/D algorithm that we considered were variable lengthinputs and real time outputs. Through this project we were able to gain valuable hands on

    experience with the entire DSP programming procedure.

  • 5/26/2018 Run Length Encoding By Surovit Roy

    45/48

    A Project Report on Image Compression

    Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 45

    REFERENCES

    Books:

    Donald B. Percival and Andrew T. Walden (2000), Wavelet Methods for Time Series Analysis, Cambridge University Press. Jensen and la Cour-Harbo, (2001), Ripples in Mathematics: the Discrete

    Wavelet Transform.

    Timothy C. Bell, Ian Witten , John Cle ary (1990), Te xt Comp ression,


Recommended