You are on page 1of 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.Ms NMIMS, Mukesh Patel School of Technology
Management and Engineering.
APRIL 2014


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 been
the 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 members
who contributed to this project which have been vital for the success of this project.




Honey Soni
Surovit Roy
Rahul Virmani
























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 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.

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 an
image while maintaining its perceived visual quality. This study concentrates on the
lossless compression of image using approximate matching technique and run length
encoding. 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 very
effective 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 present
a new and different implementation, based on Set Partitioning in Hierarchical Trees
(SPIHT), which provides even better performance than our previously reported extension
of 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 sophisticated
and 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.


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 Introduction
1.2 Need for Image Compression
1.3 Basic Types of Compression
1.4 Flow of Compression
1.5 Flow of Encoding
6
7
8
11
11
2 COMPESSION TECHNIQUES
2.1 Lossless Compression Technique.
2.2 Lossy Compression Techniques.

12
13-14
3 RUN LENGTH ENCODING
3.1 Introduction
3.2 RLE for image data
3.3 Encoding String
3.4 Decoding String
3.5 Variant of Run Length Coding
3.6 Flow Chart of Run Length Encoding
3.7 Matlab Code for Run Length Encoding
3.8 Drawbacks of Run Length Encoding 3.9 Application
of Run Length Encoding
15
16
19
20
20
22
23
25
26
4. WAVELET TRANSFORM
4.1 Introduction
4.2 Comparison of the signals using Fourier Transform.
4.3 Adoption of STFT
27
28
30
5. PROCESS INVOLVED IN COMPRESSION


5.1 Image Compression & Decompression Process
5.2 BMP file
5.3 Wavelet Forward Transform
5.4 Thresholding
5.5 Run Length Encoding and Decoding Techniques.
5.6 Inverse Wavelet Transform
32
32
35
38
39
42
6. DIGITAL SIGNAL PROCESOR


6.1 Introduction
6.2 TMS DSP Processor

43
44
7. CONCLUSION

48
8. REFERENCES

49-50




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 21
Figure 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 Stationary
signal
29
Figure 4.4
Graphical representation of Fourier Transformed Stationary
signal.
29
Figure 5.1
Steps involved in compression technique 32
Figure 5.2
BMP File format 33
Figure 5.3
Types of BMP files 34
Figure 6.1
Architecture of TMS320C54X DSP Processor 44



















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 been
known 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, the
reception 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 of
the 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, with
transmission 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 different
scales. 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 say
that 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 are
partitioned and how the significance information is conveyed are fundamentally different
from the aforementioned works. In the previous works, arithmetic coding of the bit
streams was essential to compress the ordering information as conveyed by the results of
the 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 arithmetic
coding 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 decoding
algorithms. The transmitted code or compressed image file is completely embedded, so

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 and
decoded 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 by
changing 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 of
telecommunication 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, judged
by 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 video
data across a communication link.

Communication equipments like modems, bridges, and routers use compression
schemes 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 information
understand 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 is
known by the receiver.8 Text can typically be compressed to approximately 40% of its
original 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), while
others 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 3
MB 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 be
compressed 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

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 transmittable
dimensions. 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 compression
schemes:

Scalability generally refers to a quality reduction achieved by manipulation of the bit
stream or file (without decompression and re-compression). Other names for scalability
are 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 types
of scalability:

Quality progressive or layer progressive: The bit stream successively refines the
reconstructed 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 may
be 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 processing
power 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.










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) and
Lossy Compression Technique.

Lossless compression with lossless compression, data is compressed without any loss of
data. 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 compression
algorithms 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 their
movements, 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 that
you 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

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, useful
for 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 lossy
version 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

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 the
image.
`
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 single
quantum 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 data
quantization in JPEG 2000.

Source Coding- source code is any collection of computer instructions (possibly
with comments) written using some human-readable computer language, usually
as text. 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 by
a compiler program into low-level machine 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 Image
Bitstream

A Project Report on Image Compression
Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 12

an interpreter can be used to analyze and perform the outcomes of the source code
program directly on 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 usually
allows for improved compression rates (and therefore smaller sized files).

Lossless data compression is used in many applications. For example, it is used in
the ZIP file format and in the UNIX tool gzips. It is also often used as a component within
lossy 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 exact
replication of the audio is unnecessary
Following techniques are included in lossless compression:

Huffman Coding: - This is a general technique for coding symbols based on their
statistical 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
Bitstream
Original
Image

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 of
identical 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 dictionary
is 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 dimensional
object. 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 problem
of 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 the
original 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 after
the 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 reconstructed
image.

Major performance considerations of a lossy compression scheme include:

1. Compression ratio
2. Signal - to noise ratio
3. Speed of encoding & decoding.

Lossy compression techniques includes following schemes:

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).These
coefficients 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. Only
those few significant coefficients are selected and the remaining are discarded. The
selected coefficients are considered for further quantization and entropy encoding.

2. Vector quantization: - The basic idea in this technique is to develop a dictionary of
fixed-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 of
indices that can be further entropy coded

3. Fractal coding: - The basic idea in this technique is to develop a dictionary of fixed-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 of indices that can be
further entropy coded

4. Block Truncation Coding: - In this scheme, the image is divided into non overlapping
blocks 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, the
reconstruction 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 components
containing 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.





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 data
regardless 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 have
used 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 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. 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 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 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 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 bitmap data that is being encoded.
There are several benefits to doing so. Encoding only a simple scan line at a time means

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 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 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 the
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'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 image
data. 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 of
single 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 because
the 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 sub
formats within the BMP, PCX and TGA specification.



Encoder 0101100111... Decoder
Original Image Decoded Image
Bitstream

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 for
image data consisting of 256 colors at maximum. For larger color resolutions the efficiency
of 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 pixels
instead 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 RLE4
scheme 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:












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 particular
area.

Line Coding

A variety of applications process images line by line, even if longer runs would result in a
better 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.


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 a
particular 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.




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 run
length 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 meantime
such 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 attain
encoding:

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.









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-length
encoded 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 left
corner 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 2D
tiles, 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.














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 contain
many 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 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 the individual scan lines
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.

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 that
scan lines should be individually encoded, many applications encode image data as a
continuous 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 that
an 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 been
reached. This marker is usually a unique packet, explicitly defined in the RLE

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-line
markers 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 in
the encoded image data, our application would have to decode lines 1 through 100 of the
image 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




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 of
atomic (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 RLE schemes encode runs of multiple bits in a scan line and ignore byte and word
boundaries. Only monochrome (black and white), 1-bit images contain a sufficient number
of 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 the
bit 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 individual
bits 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 the
2-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 that
follows 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 the
size of the pixel values being encoded. The number of bits or bytes per pixel is stored in the
image 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.










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 file

Syntax: 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, specify
the full pathname.

Imshow = Display Image

Syntax: imshow(i)

imshow displays the image I in a Handle Graphics

figure, where I is a
grayscale, 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 precision

In Matlab, this function returns a Boolean type value for a Boolean
input whereas Scilab function returns a Double type value.

Length = Length of vector or largest array dimension

numberOfElements = length(array)

length(array) finds the number of elements along the largest
dimension 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. MATLAB

implicitly calls
display after any variable or expression that is not terminated by a
semicolon.
To customize the display of objects, overload the disp function
instead of the display function. Display calls disp.

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 drawbacks to this method:

The minimum useful run-length size is increased from three characters to four. This
could affect 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 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 the
uncompressed 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 the
original 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.








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 suited
to 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, Pack
Bits, PCX and ILBM.

Run-length encoding is used in fax machines (combined with other techniques
into 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.




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 called
stationary 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 following
signal:

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

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.








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

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 are
almost 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 different
intervals. 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 with
the signal to obtain the Short Time Fourier Transform of the signal.
The problem with STFT goes back to Heisenberg uncertainty principle which
states that it is impossible for one to obtain which frequencies exist at which time
instance, 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 frequency
components 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 time
intervals. Also, c h o o s i n g a wi 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 in
multi 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 functions
are ideal for analyzing real physical situations in which a signal contains
discontinuities and sharp spikes

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
FILE

EXTRACT
HEADER &
PIXEL INFO.


ROW
FORWARD






COLUMN
FORWARD


COLUMN
FORWAR
D






THRESHOLD

WAVELET INVERSE TRANSFORM


INVERSE
ROW
FORWARD
INVERSE
COLUMN
FORWARD


DECODING
RUN-
LENGTH
ENCODING


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 the
images of its type.

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

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 byte
memory 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 of
header 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 represents
white.

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 represents
white.


Extraction:

This process includes the extraction of header information and pixel
information from the input image file. Pixel information varies from image to
image 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 to
overcome shortcomings of fourier transform. In this type of transform as
frequency 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 in
frequency compared to a high frequency component.








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 smoothly
changing 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), which
are characterized by jagged transitions.

Haar Wavelets:

The Haar wavelet algorithms are applied to time series
1
where the number of
samples 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 at
each 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 series
over the sampling window. The coefficients represent the average change in
the 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 samples
s
i
, s
i+1
, s
i+2
... then the Haar wavelet equations is






A Project Report on Image Compression
Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 35

where c
i
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. Wavelet
algorithms are recursive and the smoothed data becomes the input for the next
step of the wavelet transform. The
Haar wavelet scaling function
is





where a
i
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 pass
filter. 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 high
frequency change between an odd and an even value.

Low pass filter

In digital signal processing (DSP) terms, the scaling function is a low pass
filter. 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 a
smoother, 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. Each
resolution 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 of
averages 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. The
averages 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., 2
0
) is calculated.

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 by
shifting 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 window
increases 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 a
temporary array.
It is exactly reversible without the edge effects that are a problem with
other 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 may
be 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 forward
easy way to choose the threshold, although the larger the threshold that is
chosen the more error that is introduced into the process.


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 (in
absolute value) p percent of entries are set to zero.

We generally use hard thresholding in order to obtain high output efficiency
without 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 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 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.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 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 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 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 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

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 the
individual 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 detect
quickly.

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 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't
adversely 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 c
i
, c
i+1
, .. as wavelet coefficients and a
i
, a
i+1
, . as wavelet
averages or smoothed values, then the required original data s
i
, s
i+1
, can be
obtained by the following inverse wavelet equations.

s
i
= a
i
+ c
i


s
i+1
= a
i
- c
i

The obtained output data constitutes to the final decompressed image.



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 of
signals 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 been
sampled 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 be
made 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 (limited
number 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. This
processor 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

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 i nst ruct i ons 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, and
function calls. Enhanced Harvard architecture built around one program bus, three
data buses, and four address buses for increased performance and versatility. Advanced
CPU 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. Modular
architecture 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







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-chip
peripherals. 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 cycle. Instructions
with parallel store and application-specific instructions 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.
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 dedicated
adder for non-pipelined single-cycle multiply/accumulate (MAC)
operation
Exponent encoder to compute the exponent of a 40-bit accumulator
value in a single cycle
Two address generators, including eight auxiliary registers and
two 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 immediate
operands 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.
The CB and DB carry the operands that are read from data memory.

The EB carries the data to be written to memory.


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 addresses
needed 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 the
lower 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 access
memory

Memory-mapped r egi s t er s addressing uses the memory-mapped
r egi s t er s without modifying either the current DP value or the
current SP value
Stack addressing manages adding and removing items from the system
stack 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 and
data 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





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 and
two independent 40- bit accumulators.
Two address generators with eight auxiliary registers and two auxiliary
registers arithmetic units (ARAUS).
Data bus with a bus holder feature.

Application areas of DSP are considerable:

Image processing (pattern recognition, robotic vision, image
enhancement, facsimile, satellite weather map, animation).
Instrumentation and control (spectrum analysis, position and rate
control, 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).







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 to
represent 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 of
data, we not only reduce the space required to store it, we also reduce the
bandwidth 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 obtained
for audio, video or any other multimedia files.

There are two potential drawbacks to this method:
The minimum useful run-length size is increased from three characters to four. This could
affect 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 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 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 far
more 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 length
inputs and real time outputs. Through this project we were able to gain valuable hands on
experience with the entire DSP programming procedure.











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, J ohn Cleary (1990), Text Compression,
Prentice Hall, ISBN 0139119914.
Data Compression: The complete reference

Digital Image Compression Techniques

Digital Image Processing, Gonzalez

Introduction to Data Compression, Khalid Sayood
Digital image compression techniques, Majid Rabbinic, Paul W. Jones
J.M. Shapiro, \Embedded image coding using zero trees of wavelets conceits,"
IEEE Trans. Signal Processing, vol. 41, pp. 3445{3462, Dec. 1993.

M. Rabbani, and P.W. Jones, Digital Image Compression Techniques, SPIE
Opt. Eng. Press, Bellingham, Washington, 1991.

R.A. DeVore, B. Jawerth, and B.J. Lucier, \Image compression through
wavelet transform coding," IEEE Trans. Inform. Theory, vol. 38, pp. 719{746,
March 1992.

E.H. Adelson, E. Simoncelli, and R. Hingorani, \Orthogonal pyramid
transforms for image coding," Proc. SPIE, vol. 845 { Visual Comm. and Image
Proc. II, Cambridge, MA, pp. 50{ 58, Oct. 1987.

M. Antonini, M. Barlaud, P. Mathieu, and I. Daubechies, \Image coding using
wavelet transform," IEEE Trans. Image Processing, vol. 1, pp. 205{220, April
1992.





A Project Report on Image Compression
Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 46



Journals:
DeVore, R.; Jawerth, B.; and Lucier, B., (1992), Images Compression
through Wavelet Transform Coding, IEEE Trans. Information Th. 38,
719-746.

Websites:
www.wikipedia.org
http://www.dspguide.com
http://www.arturocampos.com/
http://www.ti.com/corp/docs/home.htm
TEXAS INSTRUMENTS.
http://zone.ni.com/zone/jsp/zone.jsp
NATIONAL INSTRUMENTS.
http://www.bearcave.com
http://users.rowan.edu/~polikar/homepage.html
http://en.wikipedia.org/wiki/Run-length_encodin




















A Project Report on Image Compression
Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 47













A Project Report on Image Compression
Department of Electronics & Telecommunication Engineering, MPSTME, SVKMs NMIMS 48

You might also like