You are on page 1of 55

THE JPEG IMAGE COMPRESSION

A PROJECT REPORT
Submitted in partial fulfillment of the award of degree of
BACHELOR OF TECHNOLOGY
in
ELECTRONICS AND COMMUNICATION
Under the supervision of
Ms. Shaifali Madan Arora
BY
Ankit Saroch Rahul Jindal Kushal
(1471502807) (1631502807) (1431502807)
DIRECTORATE OF ECE
MAHARAJA SURAJMAL INSTITUTE OF TECHNOLOGY
Affiliated to Guru Gobind Singh Indraprastha University
C-4E , JANAK PURI NEW DELHI 110052
DECEMBER 2010


- 1 -
DECLARATION
This is to certify that Report entitled “JPEG Image Compression” which is submitted by us in
partial fulfillment of the requirement for the award of degree B.Tech. in Electronics &
Communication Engineering to MSIT, GGSIP University, Kashmere Gate, Delhi comprises only
my original work and due acknowledgement has been made in the text to all other material used.
DATE : ANKIT SAROCH (1471502807)
RAHUL JINDAL (1631502807)
KUSHAL (1431502807)
APPROVED BY Ms. SHAIFALI MADAN ARORA
- 2 -
CERTIFICATE
This is to certify that thesis/Report entitled “JPEG Image Compression” which is submitted by
…………………………………………... in partial fulfillment of the requirement for the award of
degree B.Tech. in Electronics & Communication Engineering to MSIT, GGSIP University,
Kashmere Gate, Delhi is a record of the candidate own work carried out by him under my/our
supervision. The matter embodied in this thesis is original and has not been submitted for the
award of any other degree.


Date: Supervisor
- 3 -
- Tabl e Of Cont ent s –
DECLARATION
CERTIFICATE
TABLE OF CONTENTS
ABSTRACT
1.
1. INTRODUCTION.................................................................................................................................................................................................6
1.1 WHAT IS AN IMAGE?..............................................................................................................................................7
1.2 TRANSPARENCY....................................................................................................................................................7
1.3 FILE FORMATS......................................................................................................................................................8
1.4 BANDWIDTH AND TRANSMISSION.............................................................................................................................9
Figure 1: Download Time Comparison.................................................................................................................................10
2. AN INTRODUCTION TO IMAGE COMPRESSION.......................................................................................................................................10
2.1 THE IMAGE COMPRESSION MODEL..........................................................................................................................11
2.2 FIDELITY CRITERION............................................................................................................................................12
Figure 2: Absolute Comparizon Scale...................................................................................................................................13
Figure 3: Relative Comparison Scale.....................................................................................................................................13
2.3 INFORMATION THEORY.......................................................................................................................................13
2.4 COMPRESSION SUMMARY.....................................................................................................................................14
3 A LOOK AT SOME JPEG ALTERNATIVES....................................................................................................................................................15
3.1 GIF COMPRESSION...............................................................................................................................................15
3.2 PNG COMPRESSION............................................................................................................................................16
3.3 TIFF COMPRESSION...........................................................................................................................................18
4. COMPARISON OF IMAGE COMPRESSION TECHNIQUES.......................................................................................................................19
Figure 4: Example Image.......................................................................................................................................................20
Figure 5: Image Compression Comparison...........................................................................................................................20
Figure 6: Summary of GIF, PNG, and TIFF..........................................................................................................................21
5. THE JPEG ALGORITHM........................................................................................................................................21
5.1 PHASE ONE: DIVIDE THE IMAGE..............................................................................................................................22
Figure 7: Example of Image Division....................................................................................................................................24
5.2 PHASE TWO: CONVERSION TO THE FREQUENCY DOMAIN..........................................................................................24
Figure 8: DCT Equation.........................................................................................................................................................25
5.3 PHASE THREE: QUANTIZATION..............................................................................................................................26
Figure 9: Sample Quantization Matrix...................................................................................................................................28
Figure 10: Quantization Equation..........................................................................................................................................28
5.4 PHASE FOUR: ENTROPY CODING...........................................................................................................................29
Figure 11: Zigzag Ordered Encoding.....................................................................................................................................29
5.5 OTHER JPEG INFORMATION.................................................................................................................................30
5.5.1 Color Images.............................................................................................................................................30
5.5.2 Decompression.........................................................................................................................................31
Figure 12: Inverse DCT Equation..........................................................................................................................................32
5.5.4 Compression Ratio.....................................................................................................................................32
The compression ratio is equal to the size of the original image divided by the size of the compressed image.
This ratio gives an indication of how much compression is achieved for a particular image. Most algorithms
have a typical range of compression ratios that they can achieve over a variety of images. Because of this, it is
usually more useful to look at an average compression ratio for a particular method.........................................32
- 4 -
The compression ratio typically affects the picture quality. Generally, the higher the compression ratio, the
poorer the quality of the resulting image. The tradeoff between compression ratio and picture quality is an
important one to consider when compressing images..........................................................................................33
...........................................................................................................................................................................33
5.5.4 Sources of Loss in an Image......................................................................................................................33
5.5.5 Progressive JPEG Images.........................................................................................................................34
5.5.6 Running Time...........................................................................................................................................35
6. VARIANTS OF THE JPEG ALGORITHM.....................................................................................................................................................35
6.1 JFIF (JPEG FILE INTERCHANGE FORMAT).............................................................................................................36
Figure 13: Example of JFIF Samples.....................................................................................................................................37
6.2 JBIG COMPRESSION............................................................................................................................................37
6.3 JTIP (JPEG TILED IMAGE PYRAMID)..................................................................................................................38
Figure 14: JTIP Tiling...............................................................................................................39
............................................................................................................................................................................40
CONCLUSION...........................................................................................................................................................................................................40
REFERENCES...........................................................................................................................................................................................................41
MATHWORKS INC..................................................................................................................................................41
“INTRODUCTION” THROUGH “A QUICK COMPARISON OF IMAGE COMPRESSION TECHNIQUES”..................................................41
“THE JPEG ALGORITHM” THROUGH “OTHER JPEG INFORMATION”..................................................................................41
“VARIANTS OF THE JPEG ALGORITHM” THROUGH “CONCLUSION”....................................................................................41
ABSTRACT
In this project we have implemented the Baseline JPEG standard using MATLAB.
We have done both the encoding and decoding of grayscale images in JPEG.
With this project we have also shown the differences between the compression ratio and time spent
in encoding the images with two different approaches viz-a-viz classic DCT and fast DCT. The
project also shows the effect of coefficients on the image restored.
The steps in encoding starts with first dividing the original image in 8X8 blocks of sub-images.
Then DCT is performed on these sub-images separately. And it is followed by dividing the
resulted matrices by a Quantization Matrix. And the last step in algorithm is to make the data one-
dimensional which is done by zig-zag coding and compressed by Huffman coding, run level
coding, or arithmetic coding.
The decoding process takes the reverse process of encoding. Firstly, the bit-stream received is
converted back into two-dimensional matrices and multiplied back by Quantization Matrix. Then,
the Inverse DCT is performed and the sub-images are joined together to restore the image.
- 5 -
1. Introduction
Multimedia images have become a vital and ubiquitous component of everyday life.
The amount of information encoded in an image is quite large. Even with the advances in
bandwidth and storage capabilities, if images were not compressed many applications would be too
costly. The following research project attempts to answer the following questions: What are the
basic principles of image compression? How do we measure how efficient a compression
algorithm is? When is JPEG the best image compression algorithm? How does JPEG work?
What are the alternatives to JPEG? Do they have any advantages or disadvantages? Finally, what
is JPEG200?
- 6 -
1.1 What Is an Image?
Basically, an image is a rectangular array of dots, called pixels. The size of the image is the
number of pixels (width x height). Every pixel in an image is a certain color. When dealing with a
black and white (where each pixel is either totally white, or totally black) image, the choices are
limited since only a single bit is needed for each pixel. This type of image is good for line art,
such as a cartoon in a newspaper. Another type of colorless image is a grayscale image. Grayscale
images, often wrongly called “black and white” as well, use 8 bits per pixel, which is enough to
represent every shade of gray that a human eye can distinguish. When dealing with color images,
things get a little trickier. The number of bits per pixel is called the depth of the image (or
bitplane). A bitplane of n bits can have 2
n
colors. The human eye can distinguish about 2
24
colors,
although some claim that the number of colors the eye can distinguish is much higher. The most
common color depths are 8, 16, and 24 (although 2-bit and 4-bit images are quite common,
especially on older systems).
There are two basic ways to store color information in an image. The most direct way is to
represent each pixel's color by giving an ordered triple of numbers, which is the combination of
red, green, and blue that comprise that particular color. This is referred to as an RGB image. The
second way to store information about color is to use a table to store the triples, and use a reference
into the table for each pixel. This can markedly improve the storage requirements of an image.
1.2 Transparency
Transparency refers to the technique where certain pixels are layered on top of other pixels so
that the bottom pixels will show through the top pixels. This is sometime useful in combining two
images on top of each other. It is possible to use varying degrees of transparency, where the
- 7 -
degree of transparency is known as an alpha value. In the context of the Web, this technique is
often used to get an image to blend in well with the browser's background. Adding transparency
can be as simple as choosing an unused color in the image to be the “special transparent” color,
and wherever that color occurs, the program displaying the image knows to let the background
show through.

Transparency Example:
Non-transparent Transparent
1.3 File Formats
There are a large number of file formats (hundreds) used to represent an image, some more
common then others. Among the most popular are:
• GIF (Graphics Interchange Format)
The most common image format on the Web. Stores 1 to 8-bit color or grayscale images.
• TIFF (Tagged Image File Format)
The standard image format found in most paint, imaging, and desktop publishing programs.
Supports 1- to 24- bit images and several different compression schemes.
• SGI Image
Silicon Graphics' native image file format. Stores data in 24-bit RGB color.
• Sun Raster
Sun's native image file format; produced by many programs that run on Sun workstations.
• PICT
Macintosh's native image file format; produced by many programs that run on Macs.
Stores up to 24-bit color.
• BMP (Microsoft Windows Bitmap)
Main format supported by Microsoft Windows. Stores 1-, 4-, 8-, and 24-bit images.
- 8 -
• XBM (X Bitmap)
A format for monochrome (1-bit) images common in the X Windows system.
• JPEG File Interchange Format
Developed by the Joint Photographic Experts Group, sometimes simply called the JPEG
file format. It can store up to 24-bits of color. Some Web browsers can display JPEG
images inline (in particular, Netscape can), but this feature is not a part of the HTML
standard.
The following features are common to most bitmap files:
• Header: Found at the beginning of the file, and containing information such as the image's
size, number of colors, the compression scheme used, etc.
• Color Table: If applicable, this is usually found in the header.
• Pixel Data: The actual data values in the image.
• Footer: Not all formats include a footer, which is used to signal the end of the data.
1.4 Bandwidth and Transmission
In our high stress, high productivity society, efficiency is key. Most people do not have the
time or patience to wait for extended periods of time while an image is downloaded or retrieved.
In fact, it has been shown that the average person will only wait 20 seconds for an image to appear
on a web page. Given the fact that the average Internet user still has a 28k or 56k modem, it is
essential to keep image sizes under control. Without some type of compression, most images
would be too cumbersome and impractical for use. The following table is used to show the
- 9 -
correlation between modem speed and download time. Note that even high speed Internet users
require over one second to download the image.
Modem
Speed
Throughput – How Much
Data Per Second
Download Time
For a
40k Image
14.4k 1kB 40 seconds
28.8k 2kB 20 seconds
33.6k 3kB 13.5 seconds
56k 5kB 8 seconds
256k DSL 32kB 1.25 seconds
1.5M T1 197kB 0.2 seconds
Figure 1: Download Time Comparison
2. An Introduction to Image Compression
Image compression is the process of reducing the amount of data required to represent a digital
image. This is done by removing all redundant or unnecessary information. An uncompressed
image requires an enormous amount of data to represent it. As an example, a standard 8.5" by 11"
sheet of paper scanned at 100 dpi and restricted to black and white requires more then 100k bytes
to represent. Another example is the 276-pixel by 110-pixel banner that appears at the top of
Google.com. Uncompressed, it requires 728k of space. Image compression is thus essential for
the efficient storage, retrieval and transmission of images. In general, there are two main
categories of compression. Lossless compression involves the preservation of the image as is
(with no information and thus no detail lost). Lossy compression on the other hand, allows less
then perfect reproductions of the original image. The advantage being that, with a lossy algorithm,
one can achieve higher levels of compression because less information is needed. Various
amounts of data may be used to represent the same amount of information. Some representations
- 10 -
may be less efficient than others, depending on the amount of redundancy eliminated from the
data. When talking about images there are three main sources of redundant information:
• Coding Redundancy- This refers to the binary code used to represent greyvalues.
• Interpixel Redundancy- This refers to the correlation between adjacent pixels in an image.
• Psychovisual Redundancy - This refers to the unequal sensitivity of the human eye to different
visual information.
In comparing how much compression one algorithm achieves verses another, many people talk
about a compression ratio. A higher compression ratio indicates that one algorithm removes more
redundancy then another (and thus is more efficient). If n
1
and n
2
are the number of bits in two
datasets that represent the same image, the relative redundancy of the first dataset is defined as:
R
d
=1/C
R
, where C
R
(the compression ratio) =n
1
/n
2
The benefits of compression are immense. If an image is compressed at a ratio of 100:1, it may
be transmitted in one hundredth of the time, or transmitted at the same speed through a channel of
one-hundredth the bandwidth (ignoring the compression/decompression overhead). Since images
have become so commonplace and so essential to the function of computers, it is hard to see how
we would function without them.
2.1 The Image Compression Model
Source Channel Channel Source
Encoder Encoder Channel Decoder Decoder
Although image compression models differ in the way they compress data, there are many
general features that can be described which represent most image compression algorithms. The
source encoder is used to remove redundancy in the input image. The channel encoder is used as
- 11 -
F(m,n)
F'(m,n)
overhead in order to combat channel noise. A common example of this would be the introduction
of a parity bit. By introducing this overhead, a certain level of immunity is gained from noise that
is inherent in any storage or transmission system. The channel in this model could be either a
communication link or a storage/retrieval system. The job of the channel and source decoders is to
basically undo the work of the source and channel encoders in order to restore the image to the
user.
2.2 Fidelity Criterion
A measure is needed in order to measure the amount of data lost (if any) due to a compression
scheme. This measure is called a fidelity criterion. There are two main categories of fidelity
criterion: subjective and objective. Objective fidelity criterion, involve a quantitative approach to
error criterion. Perhaps the most common example of this is the root mean square error. A very
much related measure is the mean square signal to noise ratio. Although objective field criteria
may be useful in analyzing the amount of error involved in a compression scheme, our eyes do not
always see things as they are. Which is why the second category of fidelity criterion is important.
Subjective field criteria are quality evaluations based on a human observer. These ratings are often
averaged to come up with an evaluation of a compression scheme. There are absolute comparison
scales, which are based solely on the decompressed image, and there are relative comparison scales
that involve viewing the original and decompressed images side by side in comparison. Examples
of both scales are provided, for interest.
Value Rating Description
1 Excellent An image of extremely high quality. As good as desired.
2 Fine An image of high quality, providing enjoyable viewing.
3 Passable An image of acceptable quality.
4 Marginal An image of poor quality; one wishes to improve it.
- 12 -
5 Inferior A very poor image, but one can see it.
6 Unusable An image so bad, one can't see it.
Figure 2: Absolute Comparizon Scale
VALUE -3 -2 -1 0 1 2 3
Rating Much
Worse
Worse Slightly
Worse
Same Slightly
Better
Better Much
Better
Figure 3: Relative Comparison Scale
An obvious problem that arises is that subjective fidelity criterion may vary from person to
person. What one person sees a marginal, another may view as passable, etc.
2.3 Information Theory
In the 1940's Claude E. Shannon pioneered a field that is now the theoretical basis for most
data compression techniques. Information theory is useful in answering questions such as what is
the minimum amount of data needed to represent an image without loss of information? Or,
theoretically what is the best compression possible?
The basic premise is that the generation of information may be viewed as a probabilistic
process. The input (or source) is viewed to generate one of N possible symbols from the source
alphabet set A={a ,b , c,…, z), {0, 1}, {0, 2, 4…, 280}, etc. in unit time. The source output can be
denoted as a discrete random variable E, which is a symbol from the alphabet source along with a
corresponding probability (z). When an algorithm scans the input for an occurrence of E, the result
is a gain in information denoted by I(E), and quantified as:
I(E) = log(1/ P(E))
This relation indicated that the amount of information attributed to an event is inversely related
to the probability of that event. As an example, a certain event (P(E) = 1) leads to an I(E) = 0.
- 13 -
This makes sense, since as we know that the event is certain, observing its occurrence adds nothing
to our information. On the other hand, when a highly uncertain event occurs, a significant gain of
information is the result.
An important concept called the entropy of a source (H(z)), is defined as the average amount of
information gained by observing a particular source symbol. Basically, this allows an algorithm to
quantize the randomness of a source. The amount of randomness is quite important because the
more random a source is (the more unlikely it is to occur) the more information that is needed to
represent it. It turns out that for a fixed number of source symbols, efficiency is maximized when
all the symbols are equally likely. It is based on this principle that codewords are assigned to
represent information. There are many different schemes of assigning codewords, the most
common being the Huffman coding, run length encoding, and LZW.
2.4 Compression Summary
Image compression is achieved by removing (or reducing) redundant information. In order to
effectively do this, patterns in the data must be identified and utilized. The theoretical basis for
this is founded in Information theory, which assigns probabilities to the likelihood of the
occurrence of each symbol in the input. Symbols with a high probability of occurring are
represented with shorter bit strings (or codewords). Conversely, symbols with a low probability of
occurring are represented with longer codewords. In this way, the average length of codewords is
decreased, and redundancy is reduced. How efficient an algorithm can be, depends in part on how
the probability of the symbols is distributed, with maximum efficiency occurring when the
distribution is equal over all input symbols.
- 14 -
3 A Look at Some JPEG Alternatives
Before examining the JPEG compression algorithm, the report will now proceed to examine
some of the widely available alternatives. Each algorithm will be examined separately, with a
comparison at the end. The best algorithms to study for our purposes are GIF, PNG, and TIFF.
3.1 GIF Compression
The GIF (Graphics Interchange Format) was created in 1987 by Compuserve. It was revised in
1989. GIF uses a compression algorithm called "LZW," written by Abraham Lempel, Jacob Ziv,
and Terry Welch. Unisys patented the algorithm in 1985, and in 1995 the company made the
controversial move of asking developers to pay for the previously free LZW license. This led to
the creation of GIF alternatives such as PNG (which is discussed later). However, since GIF is one
of the oldest image file formats on the Web, it is very much embedded into the landscape of the
Internet, and it is here to stay for the near future. The LZW compression algorithm is an example
of a lossless algorithm. The GIF format is well known to be good for graphics that contain text,
computer-generated art, and/or large areas of solid color (a scenario that does not occur very often
in photographs or other real life images). GIF’s main limitation lies in the fact that it only supports
a maximum of 256 colors. It has a running time of O(m
2
), where m is the number of colors
between 2 and 256.
The first step in GIF compression is to "index" the image's color palette. This decreases the
number of colors in your image to a maximum of 256 (8-bit color). The smaller the number of
- 15 -
colors in the palette, the greater the efficiency of the algorithm. Many times, an image that is of
high quality in 256 colors can be reproduced effectively with 128 or fewer colors.
LZW compression works best with images that have horizontal bands of solid color. So if you
have eight pixels across a one-pixel row with the same color value (white, for example), the LZW
compression algorithm would see that as "8W" rather than "WWWWWWWW," which saves file
space.
Sometimes an indexed color image looks better after dithering, which is the process of mixing
existing colors to approximate colors that were previously eliminated. However, dithering leads to
an increased file size because it reduces the amount of horizontal repetition in an image.
Another factor that affects GIF file size is interlacing. If an image is interlaced, it will display
itself all at once, incrementally bringing in the details (just like progressive JPEG), as opposed to
the consecutive option, which will display itself row by row from top to bottom. Interlacing can
increase file size slightly, but is beneficial to users who have slow connections because they get to
see more of the image more quickly.
3.2 PNG Compression
The PNG (Portable Network Graphic) image format was created in 1995 by the PNG
Development Group as an alternative to GIF (the use of GIF was protested after the Unisys
decision to start charging for use of the LZW compression algorithm). The PNG (pronounced
"ping") file format uses the LZ77 compression algorithm instead, which was created in 1977 by
Lemper and Ziv (without Welch), and revised in 1978.
PNG is an open (free for developers) format that has a better average compression than GIF
and a number of interesting features including alpha transparency (so you may use the same image
on many different-colored backgrounds). It also supports 24-bit images, so you don't have to index
- 16 -
the colors like GIF. PNG is a lossless algorithm, which is used under many of the same constraints
as GIF. It has a running time of O(m
2
log m), where m is again the number of colors in the image.
Like all compression algorithms, LZ77 compression takes advantage of repeating data,
replacing repetitions with references to previous occurrences. Since some images do not compress
well with the LZ77 algorithm alone, PNG offers filtering options to rearrange pixel data before
compression. These filters take advantage of the fact that neighboring pixels are often similar in
value. Filtering does not compress data in any way; it just makes the data more suitable for
compression.
As an example, of how PNG filters work, imagine an image that is 8 pixels wide with the
following color values: 3, 13, 23, 33, 43, 53, 63, and 73. There is no redundant information here,
since all the values are unique, so LZ77 compression won't work very well on this particular row
of pixels. When the "Sub" filter is used to calculate the difference between the pixels (which is 10)
then the data that is observed becomes: 3, 10, 10, 10, 10, 10, 10, 10 (or 3, 7*10). The LZ77
compression algorithm then takes advantage of the newly created redundancy as it stores the
image.
Another filter is called the “Up” filter. It is similar to the Sub filter, but tries to find repetitions
of data in vertical pixel rows, rather than horizontal pixel rows.
The Average filter replaces a pixel with the difference between it and the average of the pixel
to the left and the pixel above it.
The Paeth (pronounced peyth) filter, created by Alan W. Paeth, works by replacing each pixel
with the difference between it and a special function of the pixel to the left, the pixel above and the
pixel to the upper left.
- 17 -
The Adaptive filter automatically applies the best filter(s) to the image. PNG allows different
filters to be used for different horizontal rows of pixels in the same image. This is the safest bet,
when choosing a filter in unknown circumstances.
PNG also has a no filter, or "None" option, which is useful when working with indexed color
or bitmap mode images.
A final factor that may influence PNG file size is interlacing, which is identical to the
interlacing described for GIF.
3.3 TIFF Compression
TIFF (Tagged Interchange File Format), developed in 1995, is a widely supported, highly
versatile format for storing and sharing images. It is utilized in many fax applications and is
widespread as a scanning output format.
The designers of the TIFF file format had three important goals in mind:
a. Extendibility. This is the ability to add new image types without affecting the
functionality of previous types.
b. Portability. TIFF was designed to be independent of the hardware platform and the
operating system on which it executes. TIFF makes very few demands upon its operating
environment. TIFF should (and does) perform equally well in a wide variety of computing
platforms such as PC, MAC, and UNIX.
c. Revisability. TIFF was designed not only to be an efficient medium for exchanging
image information but also to be usable as a native internal data format for image editing
applications.

The compression algorithms supported by TIFF are plentiful and include run length encoding,
Huffman encoding and LZW. Indeed, TIFF is one of the most versatile compression formats.
Depending on the compression used, this algorithm may be either lossy or lossless. Another effect
is that its running time is variable depending on which compression algorithm is chosen.
- 18 -
Some limitations of TIFF are that there are no provisions for storing vector graphics, text
annotation, etc (although such items could be easily constructed using TIFF extensions). Perhaps
TIFF’s biggest downfall is caused by its flexibility. An example of this is that TIFF format permits
both MSB ("Motorola") and LSB ("Intel") byte order data to be stored, with a header item
indicating which order is used. Keeping track of what is being used when can get quite
entertaining, but may lead to error prone code.
TIFF’s biggest advantage lies primarily in its highly flexible and platform-independent format,
which is supported by numerous image-processing applications. Since it was designed by
developers of printers, scanners, and monitors it has a very rich space of information elements for
colorimetry calibration, gamut tables, etc. Such information is also very useful for remote sensing
and multispectral applications. Another feature of TIFF that is also useful is the ability to
decompose an image by tiles rather than scanlines.

4. Comparison of Image Compression Techniques
Although various algorithms have been described so far, it is difficult to get a sense of how
each one compares to the other in terms of quality, efficiency, and practicality. Creating the
absolute smallest image requires that the user understand the differences between images and the
- 19 -
differences between compression methods. Knowing when to apply what algorithm is essential.
The following is a comparison of how each performs in a real world situation.

Figure 4: Example Image
The following screen shot was compressed and reproduced by all the three compression
algorithms. The results are summarized in the following table.
File size in bytes
Raw 24-
bit
921600
GIF
(LZW)
118937
TIFF
(LZW)
462124
PNG (24-
bit)
248269
PNG (8-
bit)
99584
Figure 5: Image Compression Comparison

In this case, the 8-bit PNG compression algorithm produced the file with the smallest size (and
thus greater compression). Does this mean that PNG is always the best option for any screen shot?
The answer is a resounding NO! Although there are no hard and fast rules for what is the best
algorithm for what situation, there are some basic guidelines to follow. A summary of findings of
this report may be found in the following table.
- 20 -
TIFF GIF PNG
Bits/pixel (max. color depth) 24-bit 8-bit 48-bit
Transparency
Interlace method
Compression of the image
Photographs
Line art, drawings and
images with large solid color
areas
Figure 6: Summary of GIF, PNG, and TIFF
5. The JPEG Algorithm
The Joint Photographic Experts Group developed the JPEG algorithm in the late 1980’s and
early 1990’s. They developed this new algorithm to address the problems of that era, specifically
the fact that consumer-level computers had enough processing power to manipulate and display
full color photographs. However, full color photographs required a tremendous amount of
bandwidth when transferred over a network connection, and required just as much space to store a
local copy of the image. Other compression techniques had major tradeoffs. They had either very
- 21 -
low amounts of compression, or major data loss in the image. Thus, the JPEG algorithm was
created to compress photographs with minimal data loss and high compression ratios.
Due to the nature of the compression algorithm, JPEG is excellent at compressing full-color
(24-bit) photographs, or compressing grayscale photos that include many different shades of gray.
The JPEG algorithm does not work well with web graphics, line art, scanned text, or other images
with sharp transitions at the edges of objects. The reason this is so will become clear in the
following sections. JPEG also features an adjustable compression ratio that lets a user determine
the quality and size of the final image. Images may be highly compressed with lesser quality, or
they may forego high compression, and instead be almost indistinguishable from the original.
JPEG compression and decompression consist of 4 distinct and independent phases. First, the
image is divided into 8 x 8 pixel blocks. Next, a discrete cosine transform is applied to each block
to convert the information from the spatial domain to the frequency domain. After that, the
frequency information is quantized to remove unnecessary information. Finally, standard
compression techniques compress the final bit stream. This report will analyze the compression of
a grayscale image, and will then extend the analysis to decompression and to color images.
5.1 Phase One: Divide the Image
Attempting to compress an entire image would not yield optimal results. Therefore, JPEG
divides the image into matrices of 8 x 8 pixel blocks. This allows the algorithm to take advantage
of the fact that similar colors tend to appear together in small parts of an image. Blocks begin at
the upper left part of the image, and are created going towards the lower right. If the image
dimensions are not multiples of 8, extra pixels are added to the bottom and right part of the image
to pad it to the next multiple of 8 so that we create only full blocks. The dummy values are easily
- 22 -
removed during decompression. From this point on, each block of 64 pixels is processed
separately from the others, except during a small part of the final compression step.
Phase one may optionally include a change in colorspace. Normally, 8 bits are used to
represent one pixel. Each byte in a grayscale image may have the value of 0 (fully black) through
255 (fully white). Color images have 3 bytes per pixel, one for each component of red, green, and
blue (RGB color). However, some operations are less complex if you convert these RGB values to
a different color representation. Normally, JPEG will convert RGB colorspace to YCbCr
colorspace. In YCbCr, Y is the luminance, which represents the intensity of the color. Cb and Cr
are chrominance values, and they actually describe the color itself. YCbCr tends to compress more
tightly than RGB, and any colorspace conversion can be done in linear time. The colorspace
conversion may be done before we break the image into blocks; it is up to the implementation of
the algorithm.
Finally, the algorithm subtracts 128 from each byte in the 64-byte block. This changes the
scale of the byte values from 0…255 to –128…127. Thus, the average value over a large set of
pixels will tend towards zero.
The following images show an example image, and that image divided into an 8 x 8 matrix of
pixel blocks. The images are shown at double their original sizes, since blocks are only 8 pixels
wide, which is extremely difficult to see. The image is 200 pixels by 220 pixels, which means that
the image will be separated into 700 blocks, with some padding added to the bottom of the image.
Also, remember that the division of an image is only a logical division, but in figure 7 lines are
used to add clarity.
- 23 -
Before: After:
Figure 7: Example of Image Division
5.2 Phase Two: Conversion to the Frequency Domain
At this point, it is possible to skip directly to the quantization step. However, we can greatly
assist that stage by converting the pixel information from the spatial domain to the frequency
domain. The conversion will make it easier for the quantization process to know which parts of
the image are least important, and it will de-emphasize those areas in order to save space.
Currently, each value in the block represents the intensity of one pixel (remember, our example
is a grayscale image). After converting the block to the frequency domain, each value will be the
amplitude of a unique cosine function. The cosine functions each have different frequencies. We
can represent the block by multiplying the functions with their corresponding amplitudes, then
adding the results together. However, we keep the functions separate during JPEG compression so
that we may remove the information that makes the smallest contribution to the image.
Human vision has a drop-off at higher frequencies, and de-emphasizing (or even removing
completely) higher frequency data from an image will give an image that appears very different to
a computer, but looks very close to the original to a human. The quantization stage uses this fact
to remove high frequency information, which results in a smaller representation of the image.
There are many algorithms that convert spatial information to the frequency domain. The most
obvious of which is the Fast Fourier Transform (FFT). However, due to the fact that image
- 24 -
information does not contain any imaginary components, there is an algorithm that is even faster
than an FFT. The Discrete Cosine Transform (DCT) is derived from the FFT, however it requires
fewer multiplications than the FFT since it works only with real numbers. Also, the DCT produces
fewer significant coefficients in its result, which leads to greater compression. Finally, the DCT is
made to work on one-dimensional data. Image data is given in blocks of two-dimensions, but we
may add another summing term to the DCT to make the equation two-dimensional. In other
words, applying the one-dimensional DCT once in the x direction and once in the y direction will
effectively give a two-dimensional discrete cosine transform.
The 2D discrete cosine transform equation is given in figure 8, where C(x) = 1/√2 if x is 0, and
C(x) = 1 for all other cases. Also, f (x, y) is the 8-bit image value at coordinates (x, y), and F (u, v)
is the new entry in the frequency matrix.
( ) ( ) ( ) ( )
( ) ( )
1
]
1

¸

⋅ + ⋅ +
⋅ ·
∑∑
· ·
7
0
7
0
16
1 2
cos
16
1 2
cos ,
4
1
,
x y
v y u x
y x f v C u C v u F
π π
Figure 8: DCT Equation
We begin examining this formula by realizing that only constants come before the brackets.
Next, we realize that only 16 different cosine terms will be needed for each different pair of (u, v)
values, so we may compute these ahead of time and then multiply the correct pair of cosine terms
to the spatial-domain value for that pixel. There will be 64 additions in the two summations, one
per pixel. Finally, we multiply the sum by the 3 constants to get the final value in the frequency
matrix. This continues for all (u, v) pairs in the frequency matrix. Since u and v may be any value
from 0…7, the frequency domain matrix is just as large as the spatial domain matrix.
The frequency domain matrix contains values from -1024…1023. The upper-left entry, also
known as the DC value, is the average of the entire block, and is the lowest frequency cosine
- 25 -
coefficient. As you move right the coefficients represent cosine functions in the vertical direction
that increase in frequency. Likewise, as you move down, the coefficients belong to increasing
frequency cosine functions in the horizontal direction. The highest frequency values occur at the
lower-right part of the matrix. The higher frequency values also have a natural tendency to be
significantly smaller than the low frequency coefficients since they contribute much less to the
image. Typically the entire lower-right half of the matrix is factored out after quantization. This
essentially removes half of the data per block, which is one reason why JPEG is so efficient at
compression.
Computing the DCT is the most time-consuming part of JPEG compression. Thus, it
determines the worst-case running time of the algorithm. The running time of the algorithm is
discussed in detail later. However, there are many different implementations of the discrete cosine
transform. Finding the most efficient one for the programmer’s situation is key. There are
implementations that can replace all multiplications with shift instructions and additions. Doing so
can give dramatic speedups, however it often approximates values, and thus leads to a lower
quality output image. There are also debates on how accurately certain DCT algorithms compute
the cosine coefficients, and whether or not the resulting values have adequate precision for their
situations. So any programmer should use caution when choosing an algorithm for computing a
DCT, and should be aware of every trade-off that the algorithm has.
5.3 Phase Three: Quantization
Having the data in the frequency domain allows the algorithm to discard the least significant
parts of the image. The JPEG algorithm does this by dividing each cosine coefficient in the data
matrix by some predetermined constant, and then rounding up or down to the closest integer value.
The constant values that are used in the division may be arbitrary, although research has
- 26 -
determined some very good typical values. However, since the algorithm may use any values it
wishes, and since this is the step that introduces the most loss in the image, it is a good place to
allow users to specify their desires for quality versus size.
Obviously, dividing by a high constant value can introduce more error in the rounding process,
but high constant values have another effect. As the constant gets larger the result of the division
approaches zero. This is especially true for the high frequency coefficients, since they tend to be
the smallest values in the matrix. Thus, many of the frequency values become zero. Phase four
takes advantage of this fact to further compress the data.
The algorithm uses the specified final image quality level to determine the constant values that
are used to divide the frequencies. A constant of 1 signifies no loss. On the other hand, a constant
of 255 is the maximum amount of loss for that coefficient. The constants are calculated according
to the user’s wishes and the heuristic values that are known to result in the best quality final
images. The constants are then entered into another 8 x 8 matrix, called the quantization matrix.
Each entry in the quantization matrix corresponds to exactly one entry in the frequency matrix.
Correspondence is determined simply by coordinates, the entry at (3, 5) in the quantization matrix
corresponds to entry (3, 5) in the frequency matrix.
A typical quantization matrix will be symmetrical about the diagonal, and will have lower
values in the upper left and higher values in the lower right. Since any arbitrary values could be
used during quantization, the entire quantization matrix is stored in the final JPEG file so that the
decompression routine will know the values that were used to divide each coefficient.
- 27 -
Figure 9 shows an example of a quantization matrix.
Figure 9: Sample Quantization Matrix
The equation used to calculate the quantized frequency matrix is fairly simple. The algorithm
takes a value from the frequency matrix (F) and divides it by its corresponding value in the
quantization matrix (Q). This gives the final value for the location in the quantized frequency
matrix (F
quantize
). Figure 10 shows the quantization equation that is used for each block in the
image.
( )
( )
( )
5 . 0
,
,
, +

,
_

¸
¸
·
v u Q
v u F
v u F
Quantize
Figure 10: Quantization Equation
By adding 0.5 to each value, we essentially round it off automatically when we truncate it,
without performing any comparisons. Of course, any means of rounding will work.
- 28 -
5.4 Phase Four: Entropy Coding
After quantization, the algorithm is left with blocks of 64 values, many of which are zero. Of
course, the best way to compress this type of data would be to collect all the zero values together,
which is exactly what JPEG does. The algorithm uses a zigzag ordered encoding, which collects
the high frequency quantized values into long strings of zeros.
To perform a zigzag encoding on a block, the algorithm starts at the DC value and begins
winding its way down the matrix, as shown in figure 11. This converts an 8 x 8 table into a 1 x 64
vector.
Figure 11: Zigzag Ordered Encoding
All of the values in each block are encoded in this zigzag order except for the DC value. For
all of the other values, there are two tokens that are used to represent the values in the final file.
The first token is a combination of {size, skip} values. The size value is the number of bits needed
to represent the second token, while the skip value is the number of zeros that precede this token.
- 29 -
The second token is simply the quantized frequency value, with no special encoding. At the end of
each block, the algorithm places an end-of-block sentinel so that the decoder can tell where one
block ends and the next begins.
The first token, with {size, skip} information, is encoded using Huffman coding. Huffman
coding scans the data being written and assigns fewer bits to frequently occurring data, and more
bits to infrequently occurring data. Thus, if a certain values of size and skip happen often, they
may be represented with only a couple of bits each. There will then be a lookup table that converts
the two bits to their entire value. JPEG allows the algorithm to use a standard Huffman table, and
also allows for custom tables by providing a field in the file that will hold the Huffman table.
DC values use delta encoding, which means that each DC value is compared to the previous
value, in zigzag order. Note that comparing DC values is done on a block by block basis, and does
not consider any other data within a block. This is the only instance where blocks are not treated
independently from each other. The difference between the current DC value and the previous
value is all that is included in the file. When storing the DC values, JPEG includes a size field and
then the actual DC delta value. So if the difference between two adjacent DC values is –4, JPEG
will store the size 3, since -4 requires 3 bits. Then, the actual binary value 100 is stored. The size
field for DC values is included in the Huffman coding for the other size values, so that JPEG can
achieve even higher compression of the data.
5.5 Other JPEG Information
There are other facts about JPEG that are not covered in the compression of a grayscale image.
The following sections describe other parts of the JPEG algorithm, such as decompression,
progressive JPEG encoding, and the algorithm’s running time.
5.5.1 Color Images
- 30 -
Color images are usually encoded in RGB colorspace, where each pixel has an 8-bit value for
each of the three composite colors. Thus, a color image is three times as large as a grayscale
image, and each of the components of a color image can be considered its own grayscale
representation of that particular color.
In fact, JPEG treats a color image as 3 separate grayscale images, and compresses each
component in the same way it compresses a grayscale image. However, most color JPEG files are
not three times larger than a grayscale image, since there is usually one color component that does
not occur as often as the others, in which case it will be highly compressed. Also, the Huffman
coding steps will have the opportunity to compress more values, since there are more possible
values to compress.
5.5.2 Decompression
Decompressing a JPEG image is basically the same as performing the compression steps in
reverse, and in the opposite order. It begins by retrieving the Huffman tables from the image and
decompressing the Huffman tokens in the image. Next, it decompresses the DCT values for each
block, since they will be the first things needed to decompress a block. JPEG then decompresses
the other 63 values in each block, filling in the appropriate number of zeros where appropriate.
The last step in reversing phase four is decoding the zigzag order and recreate the 8 x 8 blocks that
were originally used to compress the image.
To undo phase three, the quantization table is read from the JPEG file and each entry in every
block is then multiplied by its corresponding quantization value.
Phase two was the discrete cosine transformation of the image, where we converted the data
from the spatial domain to the frequency domain. Thus, we must do the opposite here, and convert
frequency values back to spatial values. This is easily accomplished by an inverse discrete cosine
- 31 -
transform. The IDCT takes each value in the spatial domain and examines the contributions that
each of the 64 frequency values make to that pixel.
In many cases, decompressing a JPEG image must be done more quickly than compressing the
original image. Typically, an image is compressed once, and viewed many times. Since the IDCT
is the slowest part of the decompression, choosing an implementation for the IDCT function is
very important. The same quality versus speed tradeoff that the DCT algorithm has applies here.
Faster implementations incur some quality loss in the image, and it is up to the programmer to
decide which implementation is appropriate for the particular situation. Figure 12 shows the
equation for the inverse discrete cosine transform function.
( ) ( ) ( ) ( )
( ) ( )
1
]
1

¸

⋅ + ⋅ +
·
∑∑
· ·
7
0
7
0
16
1 2
cos
16
1 2
cos ,
4
1
,
x y
v y u x
v u F v C u C y x f
π π
Figure 12: Inverse DCT Equation
Finally, the algorithm undoes phase one. If the image uses a colorspace that is different from
RGB, it is converted back during this step. Also, 128 is added to each pixel value to return the
pixels to the unsigned range of 8-bit numbers. Next, any padding values that were added to the
bottom or to the right of the image are removed. Finally, the blocks of 8 x 8 pixels are recombined
to form the final image.
5.5.4 Compression Ratio
The compression ratio is equal to the size of the original image divided by the size of the
compressed image. This ratio gives an indication of how much compression is achieved for a
particular image. Most algorithms have a typical range of compression ratios that they can achieve
- 32 -
over a variety of images. Because of this, it is usually more useful to look at an average
compression ratio for a particular method.
The compression ratio typically affects the picture quality. Generally, the higher the
compression ratio, the poorer the quality of the resulting image. The tradeoff between compression
ratio and picture quality is an important one to consider when compressing images.

5.5.4 Sources of Loss in an Image
JPEG is a lossy algorithm. Compressing an image with this algorithm will almost guarantee
that the decompressed version of the image will not match the original source image. Loss of
information happens in phases two and three of the algorithm.
In phase two, the discrete cosine transformation introduces some error into the image, however
this error is very slight. The error is due to imprecision in multiplication, rounding, and significant
error is possible if the DCT implementation chosen by the programmer is designed to trade off
quality for speed. Any errors introduced in this phase can affect any values in the image with
equal probability. It does not limit its error to any particular section of the image.
Phase three, on the other hand, is designed to eliminate data that does not contribute much to
the image. In fact, most of the loss in JPEG compression occurs during this phase. Quantization
divides each frequency value by a constant, and rounds the result. Therefore, higher constants
cause higher amounts of loss in the frequency matrix, since the rounding error will be higher. As
stated before, the algorithm is designed in this way, since the higher constants are concentrated
around the highest frequencies, and human vision is not very sensitive to those frequencies. Also,
the quantization matrix is adjustable, so a user may adjust the amount of error introduced into the
- 33 -
compressed image. Obviously, as the algorithm becomes less lossy, the image size increases.
Applications that allow the creation of JPEG images usually allow a user to specify some value
between 1 and 100, where 100 is the least lossy. By most standards, anything over 90 or 95 does
not make the picture any better to the human eye, but it does increase the file size dramatically.
Alternatively, very low values will create extremely small files, but the files will have a blocky
effect. In fact, some graphics artists use JPEG at very low quality settings (under 5) to create
stylized effects in their photos.
5.5.5 Progressive JPEG Images
A newer version of JPEG allows images to be encoded as progressive JPEG images. A
progressive image, when downloaded, will show the major features of the image very quickly, and
will then slowly become clearer as the rest of the image is received. Normally, an image is
displayed at full clarity, and is shown from top to bottom as it is received and decoded.
Progressive JPEG files are useful for slow connections, since a user can get a good idea what the
picture will be well before it finishes downloading. Note that progressive JPEG is simply a
rearrangement of data onto a more complicated order, and does not actually change any major
aspects of the JPEG format. Also, a progressive JPEG file will be the same size as a standard
JPEG file. Finally, displaying progressive JPEG images is more computationally intense than
displaying a standard JPEG, since some extra processing is needed to make the image fade into
view.
There are two main ways to implement a progressive JPEG. The first, and easiest, is to simply
display the DC values as they are received. The DC values, being the average value of the 8 x 8
block, are used to represent the entire block. Thus, the progressive image will appear as a blocky
- 34 -
image while the other values are received, but since the blocks are so small, a fairly adequate
representation of the image will be shown using just the DC values.
The alternative method is to begin by displaying just the DC information, as detailed above.
But then, as the data is received, it will begin to add some higher frequency values into the image.
This makes the image appear to gain sharpness until the final image is displayed. To implement
this, JPEG first encodes the image so that certain lower frequencies will be received very quickly.
The lower frequency values are displayed as they are received, and as more bits of each frequency
value are received they are shifted into place and the image is updated.
5.5.6 Running Time
The running time of the JPEG algorithm is dependent on the implementation of the discrete
cosine transformation step, since that step runs more slowly than any other step. In fact, all other
steps run in linear time. Implementing the DCT equation directly will result in a running time that
is ( )
3
n Ο to process all image blocks. This is slower than using a FFT directly, which we avoided
due to its use of imaginary components. However, by optimising the implementation of the DCT,
one can easily achieve a running time that is ( ) ( ) n n log
2
Ο , or possibly better. Even faster
algorithms for computing the DCT exist, but they sacrafice quality for speed. In some
applications, such as embedded systems, this may be a valid trade-off.
6. Variants of the JPEG Algorithm
Quite a few algorithms are based on JPEG. They were created for more specific purposes than
the more general JPEG algorithm. This section will discuss variations on JPEG. Also, since the
- 35 -
output stream from the JPEG algorithm must be saved to disk, we discuss the most common JPEG
file format.
6.1 JFIF (JPEG file interchange format)
JPEG is a compression algorithm, and does not define a specific file format for storing the final
data values. In order for a program to function properly there has to be a compatible file format to
store and retrieve the data. JFIF has emerged as the most popular JPEG file format. JFIF’s ease of
use and simple format that only transports pixels was quickly adopted by Internet browsers. JFIF
is now the industry standard file format for JPEG images. Though there are better image file
formats currently available and upcoming, it is questionable how successful these will be given
how ingrained JFIF is in the marketplace.
JFIF image orientation is top-down. This means that the encoding proceeds from left to right
and top to bottom. Spatial relationship of components such as the position of pixels is defined with
respect to the highest resolution component. Components are sampled along rows and columns so
a subsampled component position can be determined by the horizontal and vertical offset from the
upper left corner with respect to the highest resolution component.
The horizontal and vertical offsets of the first sample in a subsampled component, Xoffset i
[0,0] and Yoffset i [0,0], is defined to be Xoffset i [0,0] = ( Nsamples ref / Nsamples i ) / 2 - 0.5
Yoffset i [0,0] = ( Nlines ref / Nlines i ) / 2 - 0.5 where Nsamples ref is the number of samples per
line in the largest component, Nsamples i is the number of samples per line in the ith component,
Nlines ref is the number of lines in the largest component, Nlines i is the number of lines in the ith
component.
As an example, consider a 3 component image that is comprised of components having the
following dimensions:
- 36 -
Component 1: 256 samples, 288 lines
Component 2: 128 samples, 144 lines
Component 3: 64 samples, 96 lines
In a JFIF file, centers of the samples are positioned as illustrated below:
Component 1 (full)
Component 2 (down 2)
Component 3 (down 4)
Figure 13: Example of JFIF Samples
6.2 JBIG Compression
JBIG stands for Joint Bi-level Image Experts Group. JBIG is a method for lossless
compression of bi-level (two-color) image data. All bits in the images before and after
compression and decompression will be exactly the same.
JBIG also supports both sequential and progressive encoding methods. Sequential encoding
reads data from the top to bottom and from left to right of an image and encodes it as a single
image. Progressive encoding allows a series of multiple-resolution versions of the same image
data to be stored within a single JBIG data stream.
JBIG is platform-independent and implements easily over a wide variety of distributed
environments. However, a disadvantage to JBIG that will probably cause it to fail is the twenty-
four patented processes that keep JBIG from being freely distributed. The most prominent is the
IBM arithmetic Q-coder, which is an option in JPEG, but is mandatory in JBIG.
- 37 -
JBIG encodes redundant image data by comparing a pixel in a scan line with a set of pixels
already scanned by the encoder. These additional pixels are called a template, and they form a
simple map of the pattern of pixels that surround the pixel that is being encoded. The values of
these pixels are used to identify redundant patterns in the image data. These patterns are then
compressed using an adaptive arithmetic compression coder.
JBIG is capable of compressing color or grayscale images up to 255 bits per pixel. This can be
used as an alternative to lossless JPEG. JBIG has been found to produce better to equal
compression results then lossless JPEG on data with pixels up to eight bits in depth.
Progressive coding is a way to send an image gradually to a receiver instead of all at once.
During sending the receiver can build the image from low to high detail. JBIG uses discrete steps
of detail by successively doubling the resolution. For each combination of pixel values in a
context, the probability distribution of black and white pixels can be different. In an all white
context, the probability of coding a white pixel will be much greater than that of coding a black
pixel. The Q-coder assigns, just like a Huffman coder, more bits to less probable symbols, and
thus achieves very good compression. However, the Q-coder can, unlike a Huffman coder, assign
one output codebit to more than one input symbol, and thus is able to compress bi-level pixels
without explicit clustering, as would be necessary using a Huffman coder.
6.3 JTIP (JPEG Tiled Image Pyramid)
JTIP cuts an image into a group of tiled images of different resolutions. The highest level of
the pyramid is called the vignette which is 1/16 the original size and is primarily used for
browsing. The next tile is called the imagette which is ¼ the original size and is primarily used for
image comparison. The next tile is the full screen image which is the only full representation of
- 38 -
the image. Below this tile would be the high and very high definition images. These tiles being 4
and 16 times greater then the full screen image contain extreme detail. This gives the ability to
have locally increased resolution or increase the resolution of the whole image.
The primary problem with JTIP is how to adapt the size of the digital image to the screen
definition or selected window. This is avoided when the first reduction ratio is a power of 2 times
the size of the screen. Thus all tiles will be a power of 2 in relation to the screen. Tiling is used to
divide an image into smaller subimages. This allows easier buffering in memory and quicker
random access of the image.
JTIP typically uses internal tiling so each tile is encoded as part of the same JPEG data stream,
as opposed to external tiling where each tile is a separately encoded JPEG data stream. The many
advantages and disadvantages of internal versus external tiling will not be discussed here. Figure
14 shows a logical representation of the JTIP pyramid. As you go down the pyramid, the size of
the image (graphically and storage-wise) increases.
Figure 14: JTIP Tiling
- 39 -

CONCLUSION
The JPEG algorithm was created to compress photographic images, and it does this very well,
with high compression ratios. It also allows a user to choose between high quality output images,
or very small output images. The algorithm compresses images in 4 distinct phases, and does so in
( ) ( ) n n log
2
Ο time, or better. It also inspired many other algorithms that compress images and
video, and do so in a fashion very similar to JPEG. Most of the variants of JPEG take the basic
concepts of the JPEG algorithm and apply them to more specific problems.
Due to the immense number of JPEG images that exist, this algorithm will probably be in use
for at least 10 more years. This is despite the fact that better algorithms for compressing images
exist, and even better ones than those will be ready in the near future.
- 40 -
REFERENCES
MATHWORKS inc.
“Introduction” through “A Quick Comparison of Image Compression Techniques”
“A Guide to Image Processing and Picture Management”, A.E Cawkell, Gower Publishing Limited, 1994.
“The JPEG Algorithm” through “Other JPEG Information”
“Variants of the JPEG Algorithm” through “Conclusion”
- 41 -
MATLAB CODE:
function jpeg
% This is a JPEG encoding & decoding program of still image.
% Discrete Cosine transform (DCT) is performed both by classical & Chen's
% Flowgraph methods. Predefined JPEG quantization array & Zigzag order are
% used here. 'RUN', 'LEVEL' coding is used instead of Huffman coding.
% Compression ratio is compared for each DCT method. Effect of coarse and
fine quantization is
% also examined. The execution time of 2 DCT methods is also checked.
% In addition, most energatic DCT coefficients are also applied to examine
% the effect in MatLab 7.4.0 R2009b. Input is 9 gray scale pictures &
% output is 9*9=81 pictures to compare. Blocking effect is obvious.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%-------------------------- Initialization -----------------------------
% JPEG default quantization array
Q_8x8 =uint8([
16 11 10 16 24 40 51 61
12 12 14 19 26 58 60 55
14 13 16 24 40 57 69 56
14 17 22 29 51 87 80 62
18 22 37 56 68 109 103 77
24 35 55 64 81 104 113 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99]);


% this matrix (found from long observation)is usesd to select dct
coefficients.
% lowest number -> highest priority
dct_coefficient_priority_8x8 =[
1 2 6 7 15 16 28 29;
3 5 8 14 17 27 30 43;
4 9 13 18 26 31 42 44;
10 12 19 25 32 41 45 54;
11 20 24 33 40 46 53 55;
21 23 34 39 47 52 56 61;
22 35 38 48 51 57 60 62;
36 37 49 50 58 59 63 64];
% if we decide to take 10 coefficients with the most energy, we will
assign
% 99 to ignore the other coefficients and remain with a matrix of 8x8

%This suitable Zigzag order is formed from the JPEG standard
ZigZag_Order = uint8([
1 9 2 3 10 17 25 18
11 4 5 12 19 26 33 41
- 42 -
34 27 20 13 6 7 14 21
28 35 42 49 57 50 43 36
29 22 15 8 16 23 30 37
44 51 58 59 52 45 38 31
24 32 39 46 53 60 61 54
47 40 48 55 62 63 56 64]);

% Finding the reverse zigzag order (8x8 matrix)
reverse_zigzag_order_8x8 = zeros(8,8);
for k = 1:(size(ZigZag_Order,1) *size(ZigZag_Order,2))
reverse_zigzag_order_8x8(k) = find(ZigZag_Order== k);
end;

Compressed_image_size=0;
%------------------------------------------------------------------


close all;

for Image_Index = 0:8 % the whole program will be tested for 9 images (0->8)
figure; %keep the input-output for each image seperately


%--------------------------load a picture ----------------------------
switch Image_Index
case {0,1}, input_image_128x128 = im2double( imread( sprintf(
'%d.tif',Image_Index ),'tiff' ) );
otherwise, input_image_128x128 = im2double( imread( sprintf(
'%d.tif',Image_Index),'jpeg' ) );
end
%-------------------------- ------------------------------------------


%---------------- show the input image -------------------------------
subplot(3,3,1);
imshow(input_image_128x128);
title( sprintf('original image #%d',Image_Index) );
%---------------------------------------------------------------------

for Quantization_Quality = 0:1 % 0 -> coarse quantization, 1 -> fine
quantization

for DCT_type = 0:1 % 0 -> classic DCT, 1 -> Flowgraph fast DCT

for chosen_number_of_dct_coefficient = 1:63:64 % select 1 or 64 dct
coefficients


%---------------- choose energetic DCT coefficients ------------------
% matrix used to choose only the wanted number of dct coefficients
% the matrix is initialized to zeros -> zero coefficient is chosen at the
beginning
coef_selection_matrix_8x8 = zeros(8,8);

- 43 -

% this loop will choose 1 dct coefficients each time
for l=1:chosen_number_of_dct_coefficient
% find the most energetic coefficient from the mean_matrix
[y,x] =
find(dct_coefficient_priority_8x8==min(min(dct_coefficient_priority_8x8)))

% select specific coefficients by location index y,x for the image to
be compressed
coef_selection_matrix_8x8(y,x) = 1;

% set it as 99 for the chosen dct coefficient, so that in the next
loop, we will choose the "next-most-energetic" coefficient
dct_coefficient_priority_8x8(y,x) = 99;
end

% replicate the selection matrix for all the parts of the dct transform
selection_matrix_128x128 = repmat( coef_selection_matrix_8x8,16,16 );
%---------------------------------------------------------------------


tic ; % start mark for elapsed time for encoding & decoding


%------------------------- Forward DCT -------------------------------
% for each picture perform a 2 dimensional dct on 8x8 blocks.
if DCT_type==0
dct_transformed_image = Classic_DCT(input_image_128x128) .*
selection_matrix_128x128;
else
dct_transformed_image =
image_8x8_block_flowgraph_forward_dct(input_image_128x128) .*
selection_matrix_128x128;
end
%---------------------------------------------------------------------


%---------------- show the DCT of image ------------------------------
% one can use this portion to show DCT coefficients of the image
% subplot(2,2,2);
% imshow(dct_transformed_image);
% title( sprintf('8x8 DCT of image #%d',Image_Index) );
%---------------------------------------------------------------------


%normalize dct_transformed_image by the maximum coefficient value in
dct_transformed_image
Maximum_Value_of_dct_coeffieient = max(max(dct_transformed_image));
dct_transformed_image =
dct_transformed_image./Maximum_Value_of_dct_coeffieient;

%integer conversion of dct_transformed_image
dct_transformed_image_int = im2uint8( dct_transformed_image );


%-------------------- Quantization -----------------------------------
% replicate the 'Q_8x8' for at a time whole (128x128) image quantization
- 44 -
if Quantization_Quality==0
quantization_matrix_128x128 = repmat(Q_8x8,16,16 ); %for coarse
quantization
else
quantization_matrix_128x128 =
repmat(uint8(ceil(double(Q_8x8)./40)),16,16 ); %for fine quantization
end

%at a time whole image (128x128) quantization
quantized_image_128x128 = round(dct_transformed_image_int
./quantization_matrix_128x128) ; %round operation should be done here for
lossy quantization
%---------------------------------------------------------------------


% Break 8x8 block into columns
Single_column_quantized_image=im2col(quantized_image_128x128, [8
8],'distinct');


%--------------------------- zigzag ----------------------------------
% using the MatLab Matrix indexing power (specially the ':' operator)
rather than any function
ZigZaged_Single_Column_Image=Single_column_quantized_image(ZigZag_Order,:
);
%---------------------------------------------------------------------


%---------------------- Run Level Coding -----------------------------
% construct Run Level Pair from ZigZaged_Single_Column_Image
run_level_pairs=uint8([]);
for block_index=1:256 %block by block - total 256 blocks (8x8) in the
128x128 image
single_block_image_vector_64(1:64)=0;
for Temp_Vector_Index=1:64
single_block_image_vector_64(Temp_Vector_Index) =
ZigZaged_Single_Column_Image(Temp_Vector_Index, block_index); %select 1
block sequentially from the ZigZaged_Single_Column_Image
end
non_zero_value_index_array = find(single_block_image_vector_64~=0); %
index array of next non-zero entry in a block
number_of_non_zero_entries = length(non_zero_value_index_array); % #
of non-zero entries in a block

% Case 1: if first ac coefficient has no leading zeros then encode first
coefficient
if non_zero_value_index_array(1)==1,
run=0; % no leading zero
run_level_pairs=cat(1,run_level_pairs, run,
single_block_image_vector_64(non_zero_value_index_array(1)));
end

% Case 2: loop through each non-zero entry
for n=2:number_of_non_zero_entries,
% check # of leading zeros (run)
run=non_zero_value_index_array(n)-non_zero_value_index_array(n-
1)-1;
- 45 -
run_level_pairs=cat(1, run_level_pairs, run,
single_block_image_vector_64(non_zero_value_index_array(n)));
end

% Case 3: "End of Block" mark insertion
run_level_pairs=cat(1, run_level_pairs, 255, 255);
end
%---------------------------------------------------------------------


Compressed_image_size=size(run_level_pairs); % file size after
compression
Compression_Ratio = 20480/Compressed_image_size(1,1);



% % % -------------------------------------------------------------------
% % % -------------------------------------------------------------------
% % % DECODING
% % % -------------------------------------------------------------------
% % % -------------------------------------------------------------------



%---------------------- Run Level Decoding ---------------------------
% construct ZigZaged_Single_Column_Image from Run Level Pair
c=[];
for n=1:2:size(run_level_pairs), % loop through run_level_pairs
% Case 1 & Cae 2
% concatenate zeros according to 'run' value
if run_level_pairs(n)<255 % only end of block should have 255 value
zero_count=0;
zero_count=run_level_pairs(n);
for l=1:zero_count % concatenation of zeros accouring to
zero_count
c=cat(1,c,0); % single zero concatenation
end
c=cat(1,c,run_level_pairs(n+1)); % concatenate single'level'
i.e., a non zero value

% Case 3: End of Block decoding
else
number_of_trailing_zeros= 64-mod(size(c),64);
for l= 1:number_of_trailing_zeros % concatenate as much zeros
as needed to fill a block
c=cat(1,c,0);
end
end
end
%---------------------------------------------------------------------


%---------------------------------------------------------------------
% prepare the ZigZaged_Single_Column_Image vector (each column
represents 1 block) from the
% intermediate concatenated vector "c"
for i=1:256
- 46 -
for j=1:64
ZigZaged_Single_Column_Image(j,i)=c(64*(i-1)+j);
end
end
%---------------------------------------------------------------------


%--------------------------- reverse zigzag --------------------------
%reverse zigzag procedure using the matrix indexing capability of MatLab
(specially the ':' operator)
Single_column_quantized_image =
ZigZaged_Single_Column_Image(reverse_zigzag_order_8x8,:);
%---------------------------------------------------------------------


%image matrix construction from image column
quantized_image_128x128 = col2im(Single_column_quantized_image, [8 8],
[128 128], 'distinct');


%-------------------- deQuantization ---------------------------------
dct_transformed_image =
quantized_image_128x128.*quantization_matrix_128x128 ;
%---------------------------------------------------------------------


%-------------------------- Inverse DCT ------------------------------
% restore the compressed image from the given set of coeficients
if DCT_type==0
restored_image =
image_8x8_block_inv_dct( im2double(dct_transformed_image).*Maximum_Value_of_d
ct_coeffieient ); %Maximum_Value_of_dct_coeffieient is used for reverse
nornalization
else
restored_image =
image_8x8_block_flowgraph_inverse_dct( im2double(dct_transformed_image).*Maxi
mum_Value_of_dct_coeffieient ); %Maximum_Value_of_dct_coeffieient is used
for reverse nornalization
end
%---------------------------------------------------------------------


elapsed_time = toc; % time required for both enconing & decoding


%-------------------------- Show restored image ----------------------
subplot(3,3, Quantization_Quality*2^2+ DCT_type*2+
floor(chosen_number_of_dct_coefficient/64)+2);
imshow( restored_image );

if DCT_type == 0
if Quantization_Quality == 0
title( sprintf('coarse quantize\nClassic DCT\nRestored image with
%d coeffs\nCompression ratio %.2f\nTime
%f',chosen_number_of_dct_coefficient,Compression_Ratio,elapsed_time) );
else
- 47 -
title( sprintf('fine quantize\nclassic DCT\nRestored image with
%d coeffs\nCompression ratio %.2f\nTime
%f',chosen_number_of_dct_coefficient,Compression_Ratio,elapsed_time) );
end
else
if Quantization_Quality == 0
title( sprintf('coarse quantize\nFast DCT\nRestored image with %d
coeffs\nCompression ratio %.2f\nTime
%f',chosen_number_of_dct_coefficient,Compression_Ratio,elapsed_time) );
else
title( sprintf('fine quantize\nFast DCT\nRestored image with %d
coeffs\nCompression ratio %.2f\nTime
%f',chosen_number_of_dct_coefficient,Compression_Ratio,elapsed_time) );
end
end
%---------------------------------------------------------------------


end % end of coefficient number loop
end % end of DCT type loop
end % end of quantization qualoty loop
end % end of image index loop

end % end of 'jpeg' function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% I N N E R F U N C T I O N I M P L E M E N T A T I O N
%% -----------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% ------------------------------------------------------------------------
% Classic_DCT_Block_8x8 - implementation of a 2 Dimensional DCT
% assumption: input matrix is a square matrix !
% ------------------------------------------------------------------------
function out = Classic_DCT_Block_8x8( in )


% get input matrix size
N = size(in,1);

% build the matrix
n = 0:N-1;
for k = 0:N-1
if (k>0)
C(k+1,n+1) = cos(pi*(2*n+1)*k/2/N)/sqrt(N)*sqrt(2);
else
C(k+1,n+1) = cos(pi*(2*n+1)*k/2/N)/sqrt(N);
end
end
out = C*in*(C');
end % end of Classic_DCT_Block_8x8 function


% ------------------------------------------------------------------------
% pdip_inv_dct2 - implementation of an inverse 2 Dimensional DCT
% assumption: input matrix is a square matrix !
% ------------------------------------------------------------------------
function out = pdip_inv_dct2( in )
- 48 -

% get input matrix size
N = size(in,1);

% build the matrix
n = 0:N-1;
for k = 0:N-1
if (k>0)
C(k+1,n+1) = cos(pi*(2*n+1)*k/2/N)/sqrt(N)*sqrt(2);
else
C(k+1,n+1) = cos(pi*(2*n+1)*k/2/N)/sqrt(N);
end
end
out = (C')*in*C;
end


% ------------------------------------------------------------------------
% Classic_DCT - perform a block DCT for an image
% ------------------------------------------------------------------------
function transform_image = Classic_DCT( input_image )

transform_image = zeros( size( input_image,1 ),size( input_image,2 ) );
for m = 0:15
for n = 0:15
transform_image( m*8+[1:8],n*8+[1:8] ) =
Classic_DCT_Block_8x8( input_image( m*8+[1:8],n*8+[1:8] ) );
end
end
end


% ------------------------------------------------------------------------
% image_8x8_block_flowgraph_forward_dct - perform a block Flowgraph forward
DCT for an image
% ------------------------------------------------------------------------
function transform_image = image_8x8_block_flowgraph_forward_dct( input_image
)

transform_image = zeros( size( input_image,1 ),size( input_image,2 ) );
for m = 0:15
for n = 0:15
transform_image( m*8+[1:8],n*8+[1:8] ) =
flowgraph_forward_dct( input_image( m*8+[1:8],n*8+[1:8] ) );
end
end
end


% ------------------------------------------------------------------------
% image_8x8_block_inv_dct - perform a block inverse DCT for an image
% ------------------------------------------------------------------------
function restored_image = image_8x8_block_inv_dct( transform_image )

restored_image = zeros( size( transform_image,1 ),size( transform_image,2 ) );
for m = 0:15
for n = 0:15
- 49 -
restored_image( m*8+[1:8],n*8+[1:8] ) =
pdip_inv_dct2( transform_image( m*8+[1:8],n*8+[1:8] ) );
end
end
end


% ------------------------------------------------------------------------
% image_8x8_block_flowgraph_inverse_dct - perform a block Flowgraph inverse
DCT for an image
% ------------------------------------------------------------------------
function restored_image =
image_8x8_block_flowgraph_inverse_dct( transform_image )

restored_image = zeros( size( transform_image,1 ),size( transform_image,2 ) );
for m = 0:15
for n = 0:15
restored_image( m*8+[1:8],n*8+[1:8] ) =
flowgraph_inverse_dct( transform_image( m*8+[1:8],n*8+[1:8] ) );
end
end
end


% ------------------------------------------------------------------------
% FLOWGRAPH forward dct (Chen,Fralick and Smith)
% ------------------------------------------------------------------------
function [DCT_8x8] = flowgraph_forward_dct(in_8x8)

% constant cosine values will be used for both forward & inverse flowgraph DCT
c1=0.980785;
c2=0.923880;
c3=0.831470;
c4=0.707107;
c5=0.555570;
c6=0.382683;
c7=0.195090;


%---------------------------row calculation FDCT--------------------------
for row_number=1:8

%sample image value initialization from input matrix
f0=in_8x8(row_number,1);
f1=in_8x8(row_number,2);
f2=in_8x8(row_number,3);
f3=in_8x8(row_number,4);
f4=in_8x8(row_number,5);
f5=in_8x8(row_number,6);
f6=in_8x8(row_number,7);
f7=in_8x8(row_number,8);

%first stage of FLOWGRAPH (Chen,Fralick and Smith)
i0=f0+f7;
i1=f1+f6;
i2=f2+f5;
i3=f3+f4;
- 50 -
i4=f3-f4;
i5=f2-f5;
i6=f1-f6;
i7=f0-f7;

%second stage of FLOWGRAPH (Chen,Fralick and Smith)
j0=i0+i3;
j1=i1+i2;
j2=i1-i2;
j3=i0-i3;
j4=i4;
j5=(i6-i5)*c4;
j6=(i6+i5)*c4;
j7=i7;

%third stage of FLOWGRAPH (Chen,Fralick and Smith)
k0=(j0+j1)*c4;
k1=(j0-j1)*c4;
k2=(j2*c6)+(j3*c2);
k3=(j3*c6)-(j2*c2);
k4=j4+j5;
k5=j4-j5;
k6=j7-j6;
k7=j7+j6;

%fourth stage of FLOWGRAPH; 1-dimensional DCT coefficients
F0=k0/2;
F1=(k4*c7+k7*c1)/2;
F2=k2/2;
F3=(k6*c3-k5*c5)/2;
F4=k1/2;
F5=(k5*c3+k6*c5)/2;
F6=k3/2;
F7=(k7*c7-k4*c1)/2;

%DCT coefficient assignment
One_D_DCT_Row_8x8(row_number,1)=F0;
One_D_DCT_Row_8x8(row_number,2)=F1;
One_D_DCT_Row_8x8(row_number,3)=F2;
One_D_DCT_Row_8x8(row_number,4)=F3;
One_D_DCT_Row_8x8(row_number,5)=F4;
One_D_DCT_Row_8x8(row_number,6)=F5;
One_D_DCT_Row_8x8(row_number,7)=F6;
One_D_DCT_Row_8x8(row_number,8)=F7;

end %end of row calculations
%---------------------------end: row calculation FDCT---------------------


%--------------------------- column calculation FDCT----------------------
for column_number=1:8 %start of column calculation

%sample image value initialization
f0=One_D_DCT_Row_8x8(1,column_number);
f1=One_D_DCT_Row_8x8(2,column_number);
f2=One_D_DCT_Row_8x8(3,column_number);
f3=One_D_DCT_Row_8x8(4,column_number);
- 51 -
f4=One_D_DCT_Row_8x8(5,column_number);
f5=One_D_DCT_Row_8x8(6,column_number);
f6=One_D_DCT_Row_8x8(7,column_number);
f7=One_D_DCT_Row_8x8(8,column_number);

%first stage of FLOWGRAPH (Chen,Fralick and Smith)
i0=f0+f7;
i1=f1+f6;
i2=f2+f5;
i3=f3+f4;
i4=f3-f4;
i5=f2-f5;
i6=f1-f6;
i7=f0-f7;

%second stage of FLOWGRAPH (Chen,Fralick and Smith)
j0=i0+i3;
j1=i1+i2;
j2=i1-i2;
j3=i0-i3;
j4=i4;
j5=(i6-i5)*c4;
j6=(i6+i5)*c4;
j7=i7;

%third stage of FLOWGRAPH (Chen,Fralick and Smith)
k0=(j0+j1)*c4;
k1=(j0-j1)*c4;
k2=(j2*c6)+(j3*c2);
k3=(j3*c6)-(j2*c2);
k4=j4+j5;
k5=j4-j5;
k6=j7-j6;
k7=j7+j6;

%fourth stage of FLOWGRAPH; Desired DCT coefficients
F0=k0/2;
F1=(k4*c7+k7*c1)/2;
F2=k2/2;
F3=(k6*c3-k5*c5)/2;
F4=k1/2;
F5=(k5*c3+k6*c5)/2;
F6=k3/2;
F7=(k7*c7-k4*c1)/2;

%DCT coefficient assignment
DCT_8x8(1,column_number)=F0;
DCT_8x8(2,column_number)=F1;
DCT_8x8(3,column_number)=F2;
DCT_8x8(4,column_number)=F3;
DCT_8x8(5,column_number)=F4;
DCT_8x8(6,column_number)=F5;
DCT_8x8(7,column_number)=F6;
DCT_8x8(8,column_number)=F7;

end %end of column calculations
%---------------------------end: column calculation FDCT------------------
- 52 -


end % end of function flowgraph_forward_dct


% ------------------------------------------------------------------------
% FLOWGRAPH Inverse dct (Chen,Fralick and Smith)
% ------------------------------------------------------------------------
function [out_8x8] = flowgraph_inverse_dct(DCT_8x8)

% constant cosine values will be used for both forward & inverse flowgraph DCT
c1=0.980785;
c2=0.923880;
c3=0.831470;
c4=0.707107;
c5=0.555570;
c6=0.382683;
c7=0.195090;


%---------------------------row calculation Inverse DCT-------------------
for row_number=1:8

%DCT coefficient initialization
F0=DCT_8x8(row_number,1);
F1=DCT_8x8(row_number,2);
F2=DCT_8x8(row_number,3);
F3=DCT_8x8(row_number,4);
F4=DCT_8x8(row_number,5);
F5=DCT_8x8(row_number,6);
F6=DCT_8x8(row_number,7);
F7=DCT_8x8(row_number,8);

% first stage of FLOWGRAPH (Chen,Fralick and Smith)
k0=F0/2;
k1=F4/2;
k2=F2/2;
k3=F6/2;
k4=(F1/2*c7-F7/2*c1);
k5=(F5/2*c3-F3/2*c5);
k6=F5/2*c5+F3/2*c3;
k7=F1/2*c1+F7/2*c7;

% second stage of FLOWGRAPH (Chen,Fralick and Smith)
j0=(k0+k1)*c4;
j1=(k0-k1)*c4;
j2=(k2*c6-k3*c2);
j3=k2*c2+k3*c6;
j4=k4+k5;
j5=(k4-k5);
j6=(k7-k6);
j7=k7+k6;

% third stage of FLOWGRAPH (Chen,Fralick and Smith)
i0=j0+j3;
i1=j1+j2;
i2=(j1-j2);
- 53 -
i3=(j0-j3);
i4=j4;
i5=(j6-j5)*c4;
i6=(j5+j6)*c4;
i7=j7;

% fourth stage of FLOWGRAPH (Chen,Fralick and Smith)
f0=i0+i7;
f1=i1+i6;
f2=i2+i5;
f3=i3+i4;
f4=(i3-i4);
f5=(i2-i5);
f6=(i1-i6);
f7=(i0-i7);

%1 dimensional sample image vale assignment only after row calculations
One_D_IDCT_Row_8x8(row_number,1)=f0;
One_D_IDCT_Row_8x8(row_number,2)=f1;
One_D_IDCT_Row_8x8(row_number,3)=f2;
One_D_IDCT_Row_8x8(row_number,4)=f3;
One_D_IDCT_Row_8x8(row_number,5)=f4;
One_D_IDCT_Row_8x8(row_number,6)=f5;
One_D_IDCT_Row_8x8(row_number,7)=f6;
One_D_IDCT_Row_8x8(row_number,8)=f7;

end
%---------------------------end: row calculation Inverse DCT--------------


%---------------------------column calculation Inverse DCT----------------
for column_number=1:8

%DCT coefficient initialization
F0=One_D_IDCT_Row_8x8(1,column_number);
F1=One_D_IDCT_Row_8x8(2,column_number);
F2=One_D_IDCT_Row_8x8(3,column_number);
F3=One_D_IDCT_Row_8x8(4,column_number);
F4=One_D_IDCT_Row_8x8(5,column_number);
F5=One_D_IDCT_Row_8x8(6,column_number);
F6=One_D_IDCT_Row_8x8(7,column_number);
F7=One_D_IDCT_Row_8x8(8,column_number);

% first stage of FLOWGRAPH (Chen,Fralick and Smith)
k0=F0/2;
k1=F4/2;
k2=F2/2;
k3=F6/2;
k4=(F1/2*c7-F7/2*c1);
k5=(F5/2*c3-F3/2*c5);
k6=F5/2*c5+F3/2*c3;
k7=F1/2*c1+F7/2*c7;

% second stage of FLOWGRAPH (Chen,Fralick and Smith)
j0=(k0+k1)*c4;
j1=(k0-k1)*c4;
j2=(k2*c6-k3*c2);
- 54 -
j3=k2*c2+k3*c6;
j4=k4+k5;
j5=(k4-k5);
j6=(k7-k6);
j7=k7+k6;

% third stage of FLOWGRAPH (Chen,Fralick and Smith)
i0=j0+j3;
i1=j1+j2;
i2=(j1-j2);
i3=(j0-j3);
i4=j4;
i5=(j6-j5)*c4;
i6=(j5+j6)*c4;
i7=j7;

% fourth stage of FLOWGRAPH (Chen,Fralick and Smith)
f0=i0+i7;
f1=i1+i6;
f2=i2+i5;
f3=i3+i4;
f4=(i3-i4);
f5=(i2-i5);
f6=(i1-i6);
f7=(i0-i7);

% Desired sample image values assignment only after 2 dimensional inverse
transformation
out_8x8(1,column_number)=f0;
out_8x8(2,column_number)=f1;
out_8x8(3,column_number)=f2;
out_8x8(4,column_number)=f3;
out_8x8(5,column_number)=f4;
out_8x8(6,column_number)=f5;
out_8x8(7,column_number)=f6;
out_8x8(8,column_number)=f7;

end
%---------------------------end: column calculation Inverse DCT-----------


end % end of function flowgraph_inverse_dct
-------------------------------------
**************************------------------------------------------------------------------------------
**************************-----------------------------------------
- 55 -

DECLARATION

This is to certify that Report entitled “JPEG Image Compression” which is submitted by us in partial fulfillment of the requirement for the award of degree B.Tech. in Electronics & Communication Engineering to MSIT, GGSIP University, Kashmere Gate, Delhi comprises only my original work and due acknowledgement has been made in the text to all other material used.

DATE :

ANKIT SAROCH (1471502807) RAHUL JINDAL (1631502807) KUSHAL (1431502807)

APPROVED BY

Ms. SHAIFALI MADAN ARORA

-2-

CERTIFICATE

This is to certify that thesis/Report entitled “JPEG Image Compression” which is submitted by …………………………………………... in partial fulfillment of the requirement for the award of degree B.Tech. in Electronics & Communication Engineering to MSIT, GGSIP University, Kashmere Gate, Delhi is a record of the candidate own work carried out by him under my/our supervision. The matter embodied in this thesis is original and has not been submitted for the award of any other degree.

Date:

Supervisor

-3-

- Tabl e Of Cont ent s –
DECLARATION CERTIFICATE TABLE OF CONTENTS ABSTRACT 1. 1. INTRODUCTION.................................................................................................................................................................................................6

1.1 WHAT IS AN IMAGE?..............................................................................................................................................7 1.2 TRANSPARENCY....................................................................................................................................................7 1.3 FILE FORMATS......................................................................................................................................................8 1.4 BANDWIDTH AND TRANSMISSION.............................................................................................................................9
Figure 1: Download Time Comparison.................................................................................................................................10
2. AN INTRODUCTION TO IMAGE COMPRESSION.......................................................................................................................................10

2.1 THE IMAGE COMPRESSION MODEL..........................................................................................................................11 2.2 FIDELITY CRITERION............................................................................................................................................12
Figure 2: Absolute Comparizon Scale...................................................................................................................................13 Figure 3: Relative Comparison Scale.....................................................................................................................................13

2.3 2.4

INFORMATION THEORY.......................................................................................................................................13 COMPRESSION SUMMARY.....................................................................................................................................14

3 A LOOK AT SOME JPEG ALTERNATIVES....................................................................................................................................................15

3.1 GIF COMPRESSION...............................................................................................................................................15 3.2 PNG COMPRESSION............................................................................................................................................16 3.3 TIFF COMPRESSION...........................................................................................................................................18
4. COMPARISON OF IMAGE COMPRESSION TECHNIQUES.......................................................................................................................19

Figure 4: Example Image.......................................................................................................................................................20 Figure 5: Image Compression Comparison...........................................................................................................................20 Figure 6: Summary of GIF, PNG, and TIFF..........................................................................................................................21
5. THE JPEG ALGORITHM........................................................................................................................................21

5.1 PHASE ONE: DIVIDE THE IMAGE..............................................................................................................................22
Figure 7: Example of Image Division....................................................................................................................................24

5.2 5.3 5.4

PHASE TWO: CONVERSION TO THE FREQUENCY DOMAIN..........................................................................................24
Figure 8: DCT Equation.........................................................................................................................................................25

PHASE THREE: QUANTIZATION..............................................................................................................................26
Figure 9: Sample Quantization Matrix...................................................................................................................................28 Figure 10: Quantization Equation..........................................................................................................................................28

PHASE FOUR: ENTROPY CODING...........................................................................................................................29
Figure 11: Zigzag Ordered Encoding.....................................................................................................................................29

5.5 OTHER JPEG INFORMATION.................................................................................................................................30 5.5.1 Color Images.............................................................................................................................................30 5.5.2 Decompression.........................................................................................................................................31
Figure 12: Inverse DCT Equation..........................................................................................................................................32

5.5.4 Compression Ratio.....................................................................................................................................32 The compression ratio is equal to the size of the original image divided by the size of the compressed image. This ratio gives an indication of how much compression is achieved for a particular image. Most algorithms have a typical range of compression ratios that they can achieve over a variety of images. Because of this, it is usually more useful to look at an average compression ratio for a particular method.........................................32

-4-

The compression ratio typically affects the picture quality. Generally, the higher the compression ratio, the poorer the quality of the resulting image. The tradeoff between compression ratio and picture quality is an important one to consider when compressing images..........................................................................................33 ...........................................................................................................................................................................33 5.5.4 Sources of Loss in an Image......................................................................................................................33 5.5.5 Progressive JPEG Images.........................................................................................................................34 5.5.6 Running Time...........................................................................................................................................35
6. VARIANTS OF THE JPEG ALGORITHM.....................................................................................................................................................35

6.1 6.2 6.3

JFIF (JPEG FILE INTERCHANGE FORMAT).............................................................................................................36
Figure 13: Example of JFIF Samples.....................................................................................................................................37

JBIG COMPRESSION............................................................................................................................................37 JTIP (JPEG TILED IMAGE PYRAMID)..................................................................................................................38
Figure 14: JTIP Tiling...............................................................................................................39
............................................................................................................................................................................40

CONCLUSION...........................................................................................................................................................................................................40 REFERENCES...........................................................................................................................................................................................................41

MATHWORKS INC..................................................................................................................................................41 “INTRODUCTION ” THROUGH “A QUICK COMPARISON OF IMAGE COMPRESSION TECHNIQUES”..................................................41 “THE JPEG ALGORITHM” THROUGH “OTHER JPEG INFORMATION”..................................................................................41 “VARIANTS OF THE JPEG ALGORITHM ” THROUGH “CONCLUSION”....................................................................................41

ABSTRACT

In this project we have implemented the Baseline JPEG standard using MATLAB. We have done both the encoding and decoding of grayscale images in JPEG. With this project we have also shown the differences between the compression ratio and time spent in encoding the images with two different approaches viz-a-viz classic DCT and fast DCT. The project also shows the effect of coefficients on the image restored. The steps in encoding starts with first dividing the original image in 8X8 blocks of sub-images. Then DCT is performed on these sub-images separately. And it is followed by dividing the resulted matrices by a Quantization Matrix. And the last step in algorithm is to make the data onedimensional which is done by zig-zag coding and compressed by Huffman coding, run level coding, or arithmetic coding. The decoding process takes the reverse process of encoding. Firstly, the bit-stream received is converted back into two-dimensional matrices and multiplied back by Quantization Matrix. Then, the Inverse DCT is performed and the sub-images are joined together to restore the image.

-5-

Even with the advances in bandwidth and storage capabilities. Introduction Multimedia images have become a vital and ubiquitous component of everyday life. if images were not compressed many applications would be too costly.1. what is JPEG200? -6- . The amount of information encoded in an image is quite large. The following research project attempts to answer the following questions: What are the basic principles of image compression? How do we measure how efficient a compression algorithm is? When is JPEG the best image compression algorithm? How does JPEG work? What are the alternatives to JPEG? Do they have any advantages or disadvantages? Finally.

The most common color depths are 8. The number of bits per pixel is called the depth of the image (or bitplane). which is enough to represent every shade of gray that a human eye can distinguish. which is the combination of red. such as a cartoon in a newspaper. When dealing with color images.2 Transparency Transparency refers to the technique where certain pixels are layered on top of other pixels so that the bottom pixels will show through the top pixels. Another type of colorless image is a grayscale image. or totally black) image. the choices are limited since only a single bit is needed for each pixel.1. This is sometime useful in combining two images on top of each other. Grayscale images. especially on older systems). This type of image is good for line art. The most direct way is to represent each pixel's color by giving an ordered triple of numbers. This can markedly improve the storage requirements of an image. 16. green. and blue that comprise that particular color. It is possible to use varying degrees of transparency. often wrongly called “black and white” as well. There are two basic ways to store color information in an image. use 8 bits per pixel. The second way to store information about color is to use a table to store the triples. called pixels. This is referred to as an RGB image. The size of the image is the number of pixels (width x height). things get a little trickier. an image is a rectangular array of dots.1 What Is an Image? Basically. A bitplane of n bits can have 2n colors. and use a reference into the table for each pixel. 1. When dealing with a black and white (where each pixel is either totally white. where the -7- . The human eye can distinguish about 224 colors. Every pixel in an image is a certain color. and 24 (although 2-bit and 4-bit images are quite common. although some claim that the number of colors the eye can distinguish is much higher.

Among the most popular are: • GIF (Graphics Interchange Format) The most common image format on the Web. Sun Raster Sun's native image file format. SGI Image Silicon Graphics' native image file format. some more common then others. BMP (Microsoft Windows Bitmap) Main format supported by Microsoft Windows. TIFF (Tagged Image File Format) The standard image format found in most paint. Supports 1. 8-. Stores 1-. imaging.to 24. 4-. the program displaying the image knows to let the background show through. • • • • • -8- . In the context of the Web.3 File Formats There are a large number of file formats (hundreds) used to represent an image.bit images and several different compression schemes. produced by many programs that run on Macs. this technique is often used to get an image to blend in well with the browser's background. and wherever that color occurs. and 24-bit images. Stores 1 to 8-bit color or grayscale images. Stores up to 24-bit color.degree of transparency is known as an alpha value. Stores data in 24-bit RGB color. PICT Macintosh's native image file format. Adding transparency can be as simple as choosing an unused color in the image to be the “special transparent” color. produced by many programs that run on Sun workstations. Transparency Example: Non-transparent Transparent 1. and desktop publishing programs.

and containing information such as the image's size. Given the fact that the average Internet user still has a 28k or 56k modem. Most people do not have the time or patience to wait for extended periods of time while an image is downloaded or retrieved. etc. Without some type of compression. Pixel Data: The actual data values in the image. Color Table: If applicable.4 Bandwidth and Transmission In our high stress. The following table is used to show the -9- . 1. this is usually found in the header. it is essential to keep image sizes under control. but this feature is not a part of the HTML standard. Netscape can). In fact. most images would be too cumbersome and impractical for use. the compression scheme used. JPEG File Interchange Format Developed by the Joint Photographic Experts Group. Some Web browsers can display JPEG images inline (in particular. efficiency is key. sometimes simply called the JPEG file format. it has been shown that the average person will only wait 20 seconds for an image to appear on a web page. high productivity society. which is used to signal the end of the data. Footer: Not all formats include a footer.• XBM (X Bitmap) A format for monochrome (1-bit) images common in the X Windows system. • The following features are common to most bitmap files: • • • • Header: Found at the beginning of the file. It can store up to 24-bits of color. number of colors.

com. Some representations . An Introduction to Image Compression Image compression is the process of reducing the amount of data required to represent a digital image. In general. it requires 728k of space.2 seconds Figure 1: Download Time Comparison 2. Another example is the 276-pixel by 110-pixel banner that appears at the top of Google.correlation between modem speed and download time. This is done by removing all redundant or unnecessary information. one can achieve higher levels of compression because less information is needed. Uncompressed. there are two main categories of compression. allows less then perfect reproductions of the original image. An uncompressed image requires an enormous amount of data to represent it. a standard 8. Modem Speed 14.5 seconds 8 seconds 1. Lossy compression on the other hand. Various amounts of data may be used to represent the same amount of information.4k 28. The advantage being that. Lossless compression involves the preservation of the image as is (with no information and thus no detail lost). with a lossy algorithm. Image compression is thus essential for the efficient storage.5" by 11" sheet of paper scanned at 100 dpi and restricted to black and white requires more then 100k bytes to represent. retrieval and transmission of images.25 seconds 0. As an example. Note that even high speed Internet users require over one second to download the image.5M T1 Throughput – How Much Data Per Second 1kB 2kB 3kB 5kB 32kB 197kB Download Time For a 40k Image 40 seconds 20 seconds 13.6k 56k 256k DSL 1.10 - .8k 33.

Psychovisual Redundancy . The source encoder is used to remove redundancy in the input image.This refers to the binary code used to represent greyvalues.may be less efficient than others. If n1 and n2 are the number of bits in two datasets that represent the same image. In comparing how much compression one algorithm achieves verses another. where CR (the compression ratio) =n1/n2 The benefits of compression are immense. many people talk about a compression ratio.n) Although image compression models differ in the way they compress data. If an image is compressed at a ratio of 100:1.n) Source Encoder Channel Encoder Channel Channel Decoder Source Decoder F'(m. there are many general features that can be described which represent most image compression algorithms.11 - . it may be transmitted in one hundredth of the time. The channel encoder is used as . 2. When talking about images there are three main sources of redundant information: • • • Coding Redundancy. depending on the amount of redundancy eliminated from the data. or transmitted at the same speed through a channel of one-hundredth the bandwidth (ignoring the compression/decompression overhead).This refers to the correlation between adjacent pixels in an image. Interpixel Redundancy. Since images have become so commonplace and so essential to the function of computers.1 The Image Compression Model F(m. the relative redundancy of the first dataset is defined as: Rd=1/CR. A higher compression ratio indicates that one algorithm removes more redundancy then another (and thus is more efficient). it is hard to see how we would function without them.This refers to the unequal sensitivity of the human eye to different visual information.

providing enjoyable viewing. An image of high quality. Examples of both scales are provided. This measure is called a fidelity criterion. A very much related measure is the mean square signal to noise ratio.2 Fidelity Criterion A measure is needed in order to measure the amount of data lost (if any) due to a compression scheme. and there are relative comparison scales that involve viewing the original and decompressed images side by side in comparison.overhead in order to combat channel noise. As good as desired. The job of the channel and source decoders is to basically undo the work of the source and channel encoders in order to restore the image to the user. There are absolute comparison scales. a certain level of immunity is gained from noise that is inherent in any storage or transmission system. Although objective field criteria may be useful in analyzing the amount of error involved in a compression scheme. for interest. A common example of this would be the introduction of a parity bit. 2. Objective fidelity criterion. Value 1 2 3 4 Rating Excellent Fine Passable Marginal Description An image of extremely high quality. one wishes to improve it. An image of acceptable quality. our eyes do not always see things as they are. Perhaps the most common example of this is the root mean square error. The channel in this model could be either a communication link or a storage/retrieval system. which are based solely on the decompressed image. . Which is why the second category of fidelity criterion is important. involve a quantitative approach to error criterion. There are two main categories of fidelity criterion: subjective and objective. An image of poor quality. These ratings are often averaged to come up with an evaluation of a compression scheme. Subjective field criteria are quality evaluations based on a human observer. By introducing this overhead.12 - .

What one person sees a marginal. 1}. Shannon pioneered a field that is now the theoretical basis for most data compression techniques. When an algorithm scans the input for an occurrence of E. 2. a certain event (P(E) = 1) leads to an I(E) = 0. As an example. and quantified as: I(E) = log(1/ P(E)) This relation indicated that the amount of information attributed to an event is inversely related to the probability of that event. 280}. which is a symbol from the alphabet source along with a corresponding probability (z). . 2. etc. Information theory is useful in answering questions such as what is the minimum amount of data needed to represent an image without loss of information? Or. The input (or source) is viewed to generate one of N possible symbols from the source alphabet set A={a . theoretically what is the best compression possible? The basic premise is that the generation of information may be viewed as a probabilistic process. The source output can be denoted as a discrete random variable E.…. {0. but one can see it. etc. Figure 2: Absolute Comparizon Scale VALUE Rating -3 Much Worse -2 Worse -1 0 1 2 3 Slightly Same Worse Slightly Better Much Better Better Figure 3: Relative Comparison Scale An obvious problem that arises is that subjective fidelity criterion may vary from person to person.3 Information Theory In the 1940's Claude E. another may view as passable. z). c. the result is a gain in information denoted by I(E). An image so bad. one can't see it.b . in unit time. {0. 4….5 6 Inferior Unusable A very poor image.13 - .

the most common being the Huffman coding. In order to effectively do this. with maximum efficiency occurring when the distribution is equal over all input symbols. There are many different schemes of assigning codewords. since as we know that the event is certain. Conversely. run length encoding. In this way. patterns in the data must be identified and utilized. and LZW. The amount of randomness is quite important because the more random a source is (the more unlikely it is to occur) the more information that is needed to represent it. It turns out that for a fixed number of source symbols. Symbols with a high probability of occurring are represented with shorter bit strings (or codewords). depends in part on how the probability of the symbols is distributed. when a highly uncertain event occurs. this allows an algorithm to quantize the randomness of a source. Basically. The theoretical basis for this is founded in Information theory. and redundancy is reduced. a significant gain of information is the result. 2. How efficient an algorithm can be. It is based on this principle that codewords are assigned to represent information. the average length of codewords is decreased. which assigns probabilities to the likelihood of the occurrence of each symbol in the input.14 - . On the other hand. An important concept called the entropy of a source (H(z)). efficiency is maximized when all the symbols are equally likely.4 Compression Summary Image compression is achieved by removing (or reducing) redundant information.This makes sense. symbols with a low probability of occurring are represented with longer codewords. is defined as the average amount of information gained by observing a particular source symbol. . observing its occurrence adds nothing to our information.

The smaller the number of .3 A Look at Some JPEG Alternatives Before examining the JPEG compression algorithm. Each algorithm will be examined separately." written by Abraham Lempel. and it is here to stay for the near future. the report will now proceed to examine some of the widely available alternatives. where m is the number of colors between 2 and 256. and/or large areas of solid color (a scenario that does not occur very often in photographs or other real life images). computer-generated art. Jacob Ziv. it is very much embedded into the landscape of the Internet. The best algorithms to study for our purposes are GIF. It was revised in 1989. This decreases the number of colors in your image to a maximum of 256 (8-bit color).1 GIF Compression The GIF (Graphics Interchange Format) was created in 1987 by Compuserve. PNG. with a comparison at the end. GIF’s main limitation lies in the fact that it only supports a maximum of 256 colors. This led to the creation of GIF alternatives such as PNG (which is discussed later). GIF uses a compression algorithm called "LZW. since GIF is one of the oldest image file formats on the Web. However. The LZW compression algorithm is an example of a lossless algorithm. and in 1995 the company made the controversial move of asking developers to pay for the previously free LZW license.15 - . and Terry Welch. The first step in GIF compression is to "index" the image's color palette. 3. and TIFF. Unisys patented the algorithm in 1985. It has a running time of O(m2). The GIF format is well known to be good for graphics that contain text.

which is the process of mixing existing colors to approximate colors that were previously eliminated. It also supports 24-bit images. However. it will display itself all at once. incrementally bringing in the details (just like progressive JPEG).2 PNG Compression The PNG (Portable Network Graphic) image format was created in 1995 by the PNG Development Group as an alternative to GIF (the use of GIF was protested after the Unisys decision to start charging for use of the LZW compression algorithm). Another factor that affects GIF file size is interlacing. 3." which saves file space. Sometimes an indexed color image looks better after dithering.16 - . dithering leads to an increased file size because it reduces the amount of horizontal repetition in an image. for example). PNG is an open (free for developers) format that has a better average compression than GIF and a number of interesting features including alpha transparency (so you may use the same image on many different-colored backgrounds). and revised in 1978. an image that is of high quality in 256 colors can be reproduced effectively with 128 or fewer colors. which was created in 1977 by Lemper and Ziv (without Welch).colors in the palette. as opposed to the consecutive option. Interlacing can increase file size slightly. which will display itself row by row from top to bottom. the greater the efficiency of the algorithm. so you don't have to index . LZW compression works best with images that have horizontal bands of solid color. So if you have eight pixels across a one-pixel row with the same color value (white. but is beneficial to users who have slow connections because they get to see more of the image more quickly. If an image is interlaced. Many times. The PNG (pronounced "ping") file format uses the LZ77 compression algorithm instead. the LZW compression algorithm would see that as "8W" rather than "WWWWWWWW.

Like all compression algorithms. LZ77 compression takes advantage of repeating data. 63. There is no redundant information here. created by Alan W. PNG offers filtering options to rearrange pixel data before compression. Since some images do not compress well with the LZ77 algorithm alone. When the "Sub" filter is used to calculate the difference between the pixels (which is 10) then the data that is observed becomes: 3. of how PNG filters work. 13. The LZ77 compression algorithm then takes advantage of the newly created redundancy as it stores the image. 10 (or 3. 33. and 73. Filtering does not compress data in any way. 10. 43. works by replacing each pixel with the difference between it and a special function of the pixel to the left. PNG is a lossless algorithm. As an example. replacing repetitions with references to previous occurrences. 23. 10.the colors like GIF. 10. These filters take advantage of the fact that neighboring pixels are often similar in value. rather than horizontal pixel rows. where m is again the number of colors in the image. which is used under many of the same constraints as GIF. 53. It has a running time of O(m2 log m). Paeth. The Paeth (pronounced peyth) filter. imagine an image that is 8 pixels wide with the following color values: 3. 7*10). but tries to find repetitions of data in vertical pixel rows. so LZ77 compression won't work very well on this particular row of pixels. . The Average filter replaces a pixel with the difference between it and the average of the pixel to the left and the pixel above it. since all the values are unique. 10. 10. the pixel above and the pixel to the upper left. 10.17 - . Another filter is called the “Up” filter. It is similar to the Sub filter. it just makes the data more suitable for compression.

TIFF makes very few demands upon its operating environment. is a widely supported.18 - . This is the safest bet. Portability. The compression algorithms supported by TIFF are plentiful and include run length encoding. PNG allows different filters to be used for different horizontal rows of pixels in the same image. this algorithm may be either lossy or lossless. developed in 1995. A final factor that may influence PNG file size is interlacing. highly versatile format for storing and sharing images.The Adaptive filter automatically applies the best filter(s) to the image. TIFF was designed to be independent of the hardware platform and the operating system on which it executes. c. Another effect is that its running time is variable depending on which compression algorithm is chosen. This is the ability to add new image types without affecting the functionality of previous types.3 TIFF Compression TIFF (Tagged Interchange File Format). The designers of the TIFF file format had three important goals in mind: a. Depending on the compression used. It is utilized in many fax applications and is widespread as a scanning output format. when choosing a filter in unknown circumstances. 3. PNG also has a no filter. . TIFF was designed not only to be an efficient medium for exchanging image information but also to be usable as a native internal data format for image editing applications. or "None" option. TIFF should (and does) perform equally well in a wide variety of computing platforms such as PC. TIFF is one of the most versatile compression formats. Revisability. and UNIX. which is identical to the interlacing described for GIF. b. which is useful when working with indexed color or bitmap mode images. Huffman encoding and LZW. MAC. Indeed. Extendibility.

19 - . efficiency. 4. and monitors it has a very rich space of information elements for colorimetry calibration. Comparison of Image Compression Techniques Although various algorithms have been described so far. etc. TIFF’s biggest advantage lies primarily in its highly flexible and platform-independent format. it is difficult to get a sense of how each one compares to the other in terms of quality. Such information is also very useful for remote sensing and multispectral applications. scanners. with a header item indicating which order is used. etc (although such items could be easily constructed using TIFF extensions). but may lead to error prone code.Some limitations of TIFF are that there are no provisions for storing vector graphics. gamut tables. Another feature of TIFF that is also useful is the ability to decompose an image by tiles rather than scanlines. text annotation. Since it was designed by developers of printers. Keeping track of what is being used when can get quite entertaining. An example of this is that TIFF format permits both MSB ("Motorola") and LSB ("Intel") byte order data to be stored. Creating the absolute smallest image requires that the user understand the differences between images and the . Perhaps TIFF’s biggest downfall is caused by its flexibility. and practicality. which is supported by numerous image-processing applications.

20 - . Does this mean that PNG is always the best option for any screen shot? The answer is a resounding NO! Although there are no hard and fast rules for what is the best algorithm for what situation. A summary of findings of this report may be found in the following table. the 8-bit PNG compression algorithm produced the file with the smallest size (and thus greater compression). File size in bytes Raw 24921600 bit GIF 118937 (LZW) TIFF 462124 (LZW) PNG (24248269 bit) PNG (899584 bit) Figure 5: Image Compression Comparison In this case. Knowing when to apply what algorithm is essential.differences between compression methods. The following is a comparison of how each performs in a real world situation. . Figure 4: Example Image The following screen shot was compressed and reproduced by all the three compression algorithms. The results are summarized in the following table. there are some basic guidelines to follow.

Other compression techniques had major tradeoffs. They developed this new algorithm to address the problems of that era. specifically the fact that consumer-level computers had enough processing power to manipulate and display full color photographs. and TIFF 5. The JPEG Algorithm The Joint Photographic Experts Group developed the JPEG algorithm in the late 1980’s and early 1990’s.Bits/pixel (max.21 - . and required just as much space to store a local copy of the image. They had either very . drawings and images with large solid color areas TIFF 24-bit GIF 8-bit PNG 48-bit Figure 6: Summary of GIF. full color photographs required a tremendous amount of bandwidth when transferred over a network connection. PNG. color depth) Transparency Interlace method Compression of the image Photographs Line art. However.

and will then extend the analysis to decompression and to color images. The reason this is so will become clear in the following sections. Due to the nature of the compression algorithm. This allows the algorithm to take advantage of the fact that similar colors tend to appear together in small parts of an image. JPEG also features an adjustable compression ratio that lets a user determine the quality and size of the final image. or major data loss in the image. First. JPEG divides the image into matrices of 8 x 8 pixel blocks. scanned text. or other images with sharp transitions at the edges of objects. standard compression techniques compress the final bit stream.low amounts of compression. the image is divided into 8 x 8 pixel blocks. Images may be highly compressed with lesser quality. 5. JPEG is excellent at compressing full-color (24-bit) photographs. Finally. Next. Blocks begin at the upper left part of the image. or they may forego high compression. If the image dimensions are not multiples of 8. The JPEG algorithm does not work well with web graphics. Thus. extra pixels are added to the bottom and right part of the image to pad it to the next multiple of 8 so that we create only full blocks. line art. The dummy values are easily . the JPEG algorithm was created to compress photographs with minimal data loss and high compression ratios. a discrete cosine transform is applied to each block to convert the information from the spatial domain to the frequency domain. JPEG compression and decompression consist of 4 distinct and independent phases.22 - . Therefore. or compressing grayscale photos that include many different shades of gray. the frequency information is quantized to remove unnecessary information.1 Phase One: Divide the Image Attempting to compress an entire image would not yield optimal results. After that. and instead be almost indistinguishable from the original. This report will analyze the compression of a grayscale image. and are created going towards the lower right.

with some padding added to the bottom of the image. each block of 64 pixels is processed separately from the others. and any colorspace conversion can be done in linear time. but in figure 7 lines are used to add clarity. Also. The image is 200 pixels by 220 pixels. The images are shown at double their original sizes. From this point on. JPEG will convert RGB colorspace to YCbCr colorspace. 8 bits are used to represent one pixel. YCbCr tends to compress more tightly than RGB. Color images have 3 bytes per pixel. which represents the intensity of the color. and that image divided into an 8 x 8 matrix of pixel blocks. some operations are less complex if you convert these RGB values to a different color representation. The colorspace conversion may be done before we break the image into blocks. Normally. which is extremely difficult to see. it is up to the implementation of the algorithm. since blocks are only 8 pixels wide. green. Finally. the algorithm subtracts 128 from each byte in the 64-byte block. However. Phase one may optionally include a change in colorspace. and blue (RGB color). Thus. Y is the luminance. Normally. The following images show an example image. Cb and Cr are chrominance values. This changes the scale of the byte values from 0…255 to –128…127. which means that the image will be separated into 700 blocks. Each byte in a grayscale image may have the value of 0 (fully black) through 255 (fully white). In YCbCr.23 - . and they actually describe the color itself. the average value over a large set of pixels will tend towards zero. except during a small part of the final compression step.removed during decompression. . remember that the division of an image is only a logical division. one for each component of red.

There are many algorithms that convert spatial information to the frequency domain. and it will de-emphasize those areas in order to save space.Before: After: Figure 7: Example of Image Division 5. However. However. each value in the block represents the intensity of one pixel (remember. After converting the block to the frequency domain.24 - . we keep the functions separate during JPEG compression so that we may remove the information that makes the smallest contribution to the image. we can greatly assist that stage by converting the pixel information from the spatial domain to the frequency domain. The quantization stage uses this fact to remove high frequency information. The conversion will make it easier for the quantization process to know which parts of the image are least important. then adding the results together. The cosine functions each have different frequencies. However. our example is a grayscale image). Human vision has a drop-off at higher frequencies. each value will be the amplitude of a unique cosine function. Currently. which results in a smaller representation of the image. but looks very close to the original to a human. We can represent the block by multiplying the functions with their corresponding amplitudes.2 Phase Two: Conversion to the Frequency Domain At this point. and de-emphasizing (or even removing completely) higher frequency data from an image will give an image that appears very different to a computer. due to the fact that image . it is possible to skip directly to the quantization step. The most obvious of which is the Fast Fourier Transform (FFT).

v ) = 7 7 ( 2 x + 1) ⋅ uπ cos ( 2 y + 1) ⋅ vπ  1 ⋅ C ( u ) C ( v ) ∑∑ f ( x. v) pairs in the frequency matrix. This continues for all (u. y) is the 8-bit image value at coordinates (x. Image data is given in blocks of two-dimensions. but we may add another summing term to the DCT to make the equation two-dimensional. one per pixel. is the average of the entire block. f (x. so we may compute these ahead of time and then multiply the correct pair of cosine terms to the spatial-domain value for that pixel. The frequency domain matrix contains values from -1024…1023. the DCT produces fewer significant coefficients in its result. v) values. F ( u. Also. applying the one-dimensional DCT once in the x direction and once in the y direction will effectively give a two-dimensional discrete cosine transform. and C(x) = 1 for all other cases. Finally. The upper-left entry. Next. The Discrete Cosine Transform (DCT) is derived from the FFT. y). There will be 64 additions in the two summations.information does not contain any imaginary components. the DCT is made to work on one-dimensional data. Since u and v may be any value from 0…7. In other words. there is an algorithm that is even faster than an FFT. where C(x) = 1/√2 if x is 0. Finally. the frequency domain matrix is just as large as the spatial domain matrix. however it requires fewer multiplications than the FFT since it works only with real numbers. which leads to greater compression. and is the lowest frequency cosine .25 - . The 2D discrete cosine transform equation is given in figure 8. v) is the new entry in the frequency matrix. we realize that only 16 different cosine terms will be needed for each different pair of (u. we multiply the sum by the 3 constants to get the final value in the frequency matrix. Also. also known as the DC value. and F (u. y ) cos  4 16 16  x = 0 y =0  Figure 8: DCT Equation We begin examining this formula by realizing that only constants come before the brackets.

26 - . it determines the worst-case running time of the algorithm. Finding the most efficient one for the programmer’s situation is key. there are many different implementations of the discrete cosine transform. This essentially removes half of the data per block. Likewise. Computing the DCT is the most time-consuming part of JPEG compression. Doing so can give dramatic speedups. and whether or not the resulting values have adequate precision for their situations. As you move right the coefficients represent cosine functions in the vertical direction that increase in frequency. There are implementations that can replace all multiplications with shift instructions and additions. So any programmer should use caution when choosing an algorithm for computing a DCT. the coefficients belong to increasing frequency cosine functions in the horizontal direction. and then rounding up or down to the closest integer value. Typically the entire lower-right half of the matrix is factored out after quantization. The running time of the algorithm is discussed in detail later. and should be aware of every trade-off that the algorithm has. The constant values that are used in the division may be arbitrary.coefficient. which is one reason why JPEG is so efficient at compression. The JPEG algorithm does this by dividing each cosine coefficient in the data matrix by some predetermined constant. The higher frequency values also have a natural tendency to be significantly smaller than the low frequency coefficients since they contribute much less to the image. The highest frequency values occur at the lower-right part of the matrix. Thus. although research has . and thus leads to a lower quality output image. There are also debates on how accurately certain DCT algorithms compute the cosine coefficients.3 Phase Three: Quantization Having the data in the frequency domain allows the algorithm to discard the least significant parts of the image. as you move down. however it often approximates values. 5. However.

a constant of 255 is the maximum amount of loss for that coefficient. . The constants are calculated according to the user’s wishes and the heuristic values that are known to result in the best quality final images. and since this is the step that introduces the most loss in the image. the entry at (3. 5) in the quantization matrix corresponds to entry (3. However. A constant of 1 signifies no loss. the entire quantization matrix is stored in the final JPEG file so that the decompression routine will know the values that were used to divide each coefficient. This is especially true for the high frequency coefficients. A typical quantization matrix will be symmetrical about the diagonal. it is a good place to allow users to specify their desires for quality versus size.determined some very good typical values. called the quantization matrix. The constants are then entered into another 8 x 8 matrix. and will have lower values in the upper left and higher values in the lower right. many of the frequency values become zero. The algorithm uses the specified final image quality level to determine the constant values that are used to divide the frequencies. As the constant gets larger the result of the division approaches zero. but high constant values have another effect. On the other hand. since they tend to be the smallest values in the matrix. Obviously. Correspondence is determined simply by coordinates. 5) in the frequency matrix. since the algorithm may use any values it wishes. Since any arbitrary values could be used during quantization. Each entry in the quantization matrix corresponds to exactly one entry in the frequency matrix. Phase four takes advantage of this fact to further compress the data.27 - . Thus. dividing by a high constant value can introduce more error in the rounding process.

5 to each value. any means of rounding will work. The algorithm takes a value from the frequency matrix (F) and divides it by its corresponding value in the quantization matrix (Q).5    Figure 10: Quantization Equation quantize ). Figure 9: Sample Quantization Matrix The equation used to calculate the quantized frequency matrix is fairly simple.Figure 9 shows an example of a quantization matrix. without performing any comparisons. v ) =   Q ( u . . Of course. v )  FQuantize ( u. we essentially round it off automatically when we truncate it. Figure 10 shows the quantization equation that is used for each block in the By adding 0.  F ( u. v )  + 0 . This gives the final value for the location in the quantized frequency matrix (F image.28 - .

29 - . . This converts an 8 x 8 table into a 1 x 64 vector. there are two tokens that are used to represent the values in the final file. the algorithm is left with blocks of 64 values. while the skip value is the number of zeros that precede this token. which collects the high frequency quantized values into long strings of zeros. The first token is a combination of {size. the best way to compress this type of data would be to collect all the zero values together. which is exactly what JPEG does. To perform a zigzag encoding on a block. The size value is the number of bits needed to represent the second token. as shown in figure 11. For all of the other values.5. the algorithm starts at the DC value and begins winding its way down the matrix. Of course.4 Phase Four: Entropy Coding After quantization. The algorithm uses a zigzag ordered encoding. Figure 11: Zigzag Ordered Encoding All of the values in each block are encoded in this zigzag order except for the DC value. skip} values. many of which are zero.

they may be represented with only a couple of bits each.1 Color Images . The following sections describe other parts of the JPEG algorithm. Then. in zigzag order. The size field for DC values is included in the Huffman coding for the other size values. Note that comparing DC values is done on a block by block basis. progressive JPEG encoding. with no special encoding. and also allows for custom tables by providing a field in the file that will hold the Huffman table. so that JPEG can achieve even higher compression of the data. and the algorithm’s running time. since -4 requires 3 bits. The difference between the current DC value and the previous value is all that is included in the file. DC values use delta encoding. JPEG includes a size field and then the actual DC delta value. Huffman coding scans the data being written and assigns fewer bits to frequently occurring data. if a certain values of size and skip happen often. JPEG will store the size 3. and more bits to infrequently occurring data. There will then be a lookup table that converts the two bits to their entire value. with {size. the algorithm places an end-of-block sentinel so that the decoder can tell where one block ends and the next begins. At the end of each block. This is the only instance where blocks are not treated independently from each other. JPEG allows the algorithm to use a standard Huffman table. is encoded using Huffman coding. So if the difference between two adjacent DC values is –4. skip} information. Thus.5.The second token is simply the quantized frequency value. The first token. such as decompression.5 Other JPEG Information There are other facts about JPEG that are not covered in the compression of a grayscale image. When storing the DC values. and does not consider any other data within a block. which means that each DC value is compared to the previous value.30 - . 5. 5. the actual binary value 100 is stored.

Thus.31 - . The last step in reversing phase four is decoding the zigzag order and recreate the 8 x 8 blocks that were originally used to compress the image. Phase two was the discrete cosine transformation of the image. since there are more possible values to compress. and compresses each component in the same way it compresses a grayscale image.Color images are usually encoded in RGB colorspace. and in the opposite order. in which case it will be highly compressed. JPEG treats a color image as 3 separate grayscale images. the quantization table is read from the JPEG file and each entry in every block is then multiplied by its corresponding quantization value. This is easily accomplished by an inverse discrete cosine . It begins by retrieving the Huffman tables from the image and decompressing the Huffman tokens in the image. JPEG then decompresses the other 63 values in each block. since they will be the first things needed to decompress a block. since there is usually one color component that does not occur as often as the others. To undo phase three. it decompresses the DCT values for each block. a color image is three times as large as a grayscale image. and each of the components of a color image can be considered its own grayscale representation of that particular color.5. most color JPEG files are not three times larger than a grayscale image. the Huffman coding steps will have the opportunity to compress more values. where we converted the data from the spatial domain to the frequency domain. 5. Next. However. and convert frequency values back to spatial values. where each pixel has an 8-bit value for each of the three composite colors. we must do the opposite here. filling in the appropriate number of zeros where appropriate. Also.2 Decompression Decompressing a JPEG image is basically the same as performing the compression steps in reverse. In fact. Thus.

Most algorithms have a typical range of compression ratios that they can achieve . Typically. f ( x. Also. 128 is added to each pixel value to return the pixels to the unsigned range of 8-bit numbers.transform. the blocks of 8 x 8 pixels are recombined to form the final image. The same quality versus speed tradeoff that the DCT algorithm has applies here. and viewed many times.32 - . Next. the algorithm undoes phase one.4 Compression Ratio The compression ratio is equal to the size of the original image divided by the size of the compressed image. and it is up to the programmer to decide which implementation is appropriate for the particular situation. y ) = ( 2 x + 1) ⋅ uπ cos ( 2 y + 1) ⋅ vπ  1 7 7 ∑∑ C ( u ) C ( v ) F ( u. 5. This ratio gives an indication of how much compression is achieved for a particular image. an image is compressed once. In many cases. Faster implementations incur some quality loss in the image. Figure 12 shows the equation for the inverse discrete cosine transform function. it is converted back during this step. Since the IDCT is the slowest part of the decompression. If the image uses a colorspace that is different from RGB. The IDCT takes each value in the spatial domain and examines the contributions that each of the 64 frequency values make to that pixel. any padding values that were added to the bottom or to the right of the image are removed. decompressing a JPEG image must be done more quickly than compressing the original image. Finally. choosing an implementation for the IDCT function is very important. v ) cos  4  x =0 y =0 16 16  Figure 12: Inverse DCT Equation Finally.5.

Phase three. rounding.5. higher constants cause higher amounts of loss in the frequency matrix. Therefore. is designed to eliminate data that does not contribute much to the image. The compression ratio typically affects the picture quality. Because of this. Also. Generally. since the rounding error will be higher. the quantization matrix is adjustable. the algorithm is designed in this way. the poorer the quality of the resulting image. and rounds the result. so a user may adjust the amount of error introduced into the . and human vision is not very sensitive to those frequencies. Loss of information happens in phases two and three of the algorithm. however this error is very slight.33 - . Compressing an image with this algorithm will almost guarantee that the decompressed version of the image will not match the original source image. the higher the compression ratio.over a variety of images. The error is due to imprecision in multiplication. and significant error is possible if the DCT implementation chosen by the programmer is designed to trade off quality for speed. since the higher constants are concentrated around the highest frequencies. it is usually more useful to look at an average compression ratio for a particular method. on the other hand. It does not limit its error to any particular section of the image. Any errors introduced in this phase can affect any values in the image with equal probability. the discrete cosine transformation introduces some error into the image. In phase two. most of the loss in JPEG compression occurs during this phase. 5. Quantization divides each frequency value by a constant. As stated before. The tradeoff between compression ratio and picture quality is an important one to consider when compressing images. In fact.4 Sources of Loss in an Image JPEG is a lossy algorithm.

and easiest. but it does increase the file size dramatically. some graphics artists use JPEG at very low quality settings (under 5) to create stylized effects in their photos. an image is displayed at full clarity.5 Progressive JPEG Images A newer version of JPEG allows images to be encoded as progressive JPEG images. displaying progressive JPEG images is more computationally intense than displaying a standard JPEG. A progressive image. very low values will create extremely small files. since some extra processing is needed to make the image fade into view. being the average value of the 8 x 8 block. is to simply display the DC values as they are received. anything over 90 or 95 does not make the picture any better to the human eye. as the algorithm becomes less lossy. Obviously. In fact. but the files will have a blocky effect. are used to represent the entire block. and will then slowly become clearer as the rest of the image is received. 5. the image size increases. a progressive JPEG file will be the same size as a standard JPEG file. By most standards. There are two main ways to implement a progressive JPEG. Progressive JPEG files are useful for slow connections. The first. Applications that allow the creation of JPEG images usually allow a user to specify some value between 1 and 100. Also. and does not actually change any major aspects of the JPEG format. Normally. Note that progressive JPEG is simply a rearrangement of data onto a more complicated order. the progressive image will appear as a blocky . Alternatively. since a user can get a good idea what the picture will be well before it finishes downloading. where 100 is the least lossy. and is shown from top to bottom as it is received and decoded. Finally.5.compressed image. when downloaded. The DC values.34 - . will show the major features of the image very quickly. Thus.

To implement this. Variants of the JPEG Algorithm Quite a few algorithms are based on JPEG. a fairly adequate representation of the image will be shown using just the DC values. JPEG first encodes the image so that certain lower frequencies will be received very quickly.5. or possibly better. They were created for more specific purposes than the more general JPEG algorithm. The alternative method is to begin by displaying just the DC information. This is slower than using a FFT directly. In fact. since the . ( ) ( ) Even faster In some 6. all other steps run in linear time. this may be a valid trade-off. algorithms for computing the DCT exist. This section will discuss variations on JPEG.35 - . by optimising the implementation of the DCT. But then. since that step runs more slowly than any other step. This makes the image appear to gain sharpness until the final image is displayed. one can easily achieve a running time that is Ο n 2 log ( n ) . Also.image while the other values are received. The lower frequency values are displayed as they are received. 5. Implementing the DCT equation directly will result in a running time that is Ο n 3 to process all image blocks. but since the blocks are so small. as detailed above.6 Running Time The running time of the JPEG algorithm is dependent on the implementation of the discrete cosine transformation step. However. and as more bits of each frequency value are received they are shifted into place and the image is updated. it will begin to add some higher frequency values into the image. such as embedded systems. but they sacrafice quality for speed. which we avoided due to its use of imaginary components. as the data is received. applications.

5 where Nsamples ref is the number of samples per line in the largest component. we discuss the most common JPEG file format. Nlines ref is the number of lines in the largest component. Components are sampled along rows and columns so a subsampled component position can be determined by the horizontal and vertical offset from the upper left corner with respect to the highest resolution component. it is questionable how successful these will be given how ingrained JFIF is in the marketplace.0] = ( Nlines ref / Nlines i ) / 2 . JFIF’s ease of use and simple format that only transports pixels was quickly adopted by Internet browsers. is defined to be Xoffset i [0. consider a 3 component image that is comprised of components having the following dimensions: . Nlines i is the number of lines in the ith component.1 JFIF (JPEG file interchange format) JPEG is a compression algorithm. This means that the encoding proceeds from left to right and top to bottom. JFIF has emerged as the most popular JPEG file format. The horizontal and vertical offsets of the first sample in a subsampled component. Though there are better image file formats currently available and upcoming.output stream from the JPEG algorithm must be saved to disk. JFIF image orientation is top-down. and does not define a specific file format for storing the final data values.0.0] and Yoffset i [0. As an example.0]. Xoffset i [0.5 Yoffset i [0. In order for a program to function properly there has to be a compatible file format to store and retrieve the data. Nsamples i is the number of samples per line in the ith component. Spatial relationship of components such as the position of pixels is defined with respect to the highest resolution component. JFIF is now the industry standard file format for JPEG images.0.0] = ( Nsamples ref / Nsamples i ) / 2 . 6.36 - .

Progressive encoding allows a series of multiple-resolution versions of the same image data to be stored within a single JBIG data stream. compression of bi-level (two-color) image data. JBIG is platform-independent and implements easily over a wide variety of distributed environments. 144 lines Component 3: 64 samples. JBIG also supports both sequential and progressive encoding methods. 288 lines Component 2: 128 samples.37 - . JBIG is a method for lossless All bits in the images before and after compression and decompression will be exactly the same. However. a disadvantage to JBIG that will probably cause it to fail is the twentyfour patented processes that keep JBIG from being freely distributed. The most prominent is the IBM arithmetic Q-coder. centers of the samples are positioned as illustrated below: Component 1 (full) Component 2 (down 2) Component 3 (down 4) Figure 13: Example of JFIF Samples 6. Sequential encoding reads data from the top to bottom and from left to right of an image and encodes it as a single image. which is an option in JPEG. 96 lines In a JFIF file.Component 1: 256 samples.2 JBIG Compression JBIG stands for Joint Bi-level Image Experts Group. but is mandatory in JBIG. .

and thus achieves very good compression. During sending the receiver can build the image from low to high detail.3 JTIP (JPEG Tiled Image Pyramid) JTIP cuts an image into a group of tiled images of different resolutions. For each combination of pixel values in a context. These patterns are then compressed using an adaptive arithmetic compression coder. and they form a simple map of the pattern of pixels that surround the pixel that is being encoded. the probability of coding a white pixel will be much greater than that of coding a black pixel. 6. The values of these pixels are used to identify redundant patterns in the image data. and thus is able to compress bi-level pixels without explicit clustering. In an all white context. assign one output codebit to more than one input symbol. However.JBIG encodes redundant image data by comparing a pixel in a scan line with a set of pixels already scanned by the encoder. JBIG has been found to produce better to equal compression results then lossless JPEG on data with pixels up to eight bits in depth. The Q-coder assigns. The highest level of the pyramid is called the vignette which is 1/16 the original size and is primarily used for browsing. The next tile is called the imagette which is ¼ the original size and is primarily used for image comparison. This can be used as an alternative to lossless JPEG. just like a Huffman coder. the Q-coder can. These additional pixels are called a template. as would be necessary using a Huffman coder. JBIG uses discrete steps of detail by successively doubling the resolution. The next tile is the full screen image which is the only full representation of . unlike a Huffman coder. JBIG is capable of compressing color or grayscale images up to 255 bits per pixel. the probability distribution of black and white pixels can be different.38 - . more bits to less probable symbols. Progressive coding is a way to send an image gradually to a receiver instead of all at once.

Tiling is used to divide an image into smaller subimages. the size of the image (graphically and storage-wise) increases. The primary problem with JTIP is how to adapt the size of the digital image to the screen definition or selected window. Figure 14: JTIP Tiling . This is avoided when the first reduction ratio is a power of 2 times the size of the screen. The many advantages and disadvantages of internal versus external tiling will not be discussed here. These tiles being 4 and 16 times greater then the full screen image contain extreme detail. As you go down the pyramid. Below this tile would be the high and very high definition images. This gives the ability to have locally increased resolution or increase the resolution of the whole image. Thus all tiles will be a power of 2 in relation to the screen. Figure 14 shows a logical representation of the JTIP pyramid.the image. JTIP typically uses internal tiling so each tile is encoded as part of the same JPEG data stream. This allows easier buffering in memory and quicker random access of the image.39 - . as opposed to external tiling where each tile is a separately encoded JPEG data stream.

Most of the variants of JPEG take the basic concepts of the JPEG algorithm and apply them to more specific problems. The algorithm compresses images in 4 distinct phases. this algorithm will probably be in use for at least 10 more years. and does so in Ο n 2 log ( n ) time.CONCLUSION The JPEG algorithm was created to compress photographic images.40 - . It also allows a user to choose between high quality output images. and it does this very well. or better. with high compression ratios. and even better ones than those will be ready in the near future. It also inspired many other algorithms that compress images and video. This is despite the fact that better algorithms for compressing images exist. Due to the immense number of JPEG images that exist. and do so in a fashion very similar to JPEG. or very small output images. ( ) .

1994. A. “Introduction” through “A Quick Comparison of Image Compression Techniques” “A Guide to Image Processing and Picture Management”. “The JPEG Algorithm” through “Other JPEG Information” “Variants of the JPEG Algorithm” through “Conclusion” .E Cawkell. Gower Publishing Limited.REFERENCES MATHWORKS inc.41 - .

% lowest number -> highest priority dct_coefficient_priority_8x8 =[ 1 2 6 7 15 16 28 29.4. 4 9 13 18 26 31 42 44. 'RUN'.0 R2009b. 36 37 49 50 58 59 63 64]. Blocking effect is obvious. 11 20 24 33 40 46 53 55.42 - . most energatic DCT coefficients are also applied to examine % the effect in MatLab 7. 3 5 8 14 17 27 30 43. % In addition. % if we decide to take 10 coefficients with the most energy. 'LEVEL' coding is used instead of Huffman coding. Predefined JPEG quantization array & Zigzag order are % used here. % Discrete Cosine transform (DCT) is performed both by classical & Chen's % Flowgraph methods.MATLAB CODE: function jpeg % This is a JPEG encoding & decoding program of still image. we will assign % 99 to ignore the other coefficients and remain with a matrix of 8x8 %This suitable Zigzag order is formed from the ZigZag_Order = uint8([ 1 9 2 3 10 17 25 18 11 4 5 12 19 26 33 41 JPEG standard . 22 35 38 48 51 57 60 62. % Compression ratio is compared for each DCT method. Input is 9 gray scale pictures & % output is 9*9=81 pictures to compare. Effect of coarse and fine quantization is % also examined. % this matrix (found from long observation)is usesd to select dct coefficients. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %-------------------------% JPEG default quantization Q_8x8 =uint8([ 16 11 10 16 24 40 12 12 14 19 26 58 14 13 16 24 40 57 14 17 22 29 51 87 18 22 37 56 68 109 24 35 55 64 81 104 49 64 78 87 103 121 72 92 95 98 112 100 Initialization ----------------------------array 51 61 60 55 69 56 80 62 103 77 113 92 120 101 103 99]). 21 23 34 39 47 52 56 61. The execution time of 2 DCT methods is also checked. 10 12 19 25 32 41 45 54.

for Image_Index = 0:8 % the whole program will be tested for 9 images (0->8) figure. title( sprintf('original image #%d'.Image_Index).8).Image_Index ). for k = 1:(size(ZigZag_Order.show the input image ------------------------------subplot(3. 1 -> fine quantization for DCT_type = 0:1 % 0 -> classic DCT. . end. % Finding the reverse zigzag order (8x8 matrix) reverse_zigzag_order_8x8 = zeros(8. Compressed_image_size=0. input_image_128x128 = im2double( imread( sprintf( '%d.choose energetic DCT coefficients -----------------% matrix used to choose only the wanted number of dct coefficients % the matrix is initialized to zeros -> zero coefficient is chosen at the beginning coef_selection_matrix_8x8 = zeros(8.tif'. %keep the input-output for each image seperately %--------------------------load a picture ---------------------------switch Image_Index case {0. otherwise. input_image_128x128 = im2double( imread( sprintf( '%d.tif'.-----------------------------------------%---------------.8).'tiff' ) ).Image_Index) ). 1 -> Flowgraph fast DCT % select 1 or 64 dct for chosen_number_of_dct_coefficient = 1:63:64 coefficients %---------------. end %-------------------------.1) *size(ZigZag_Order. %--------------------------------------------------------------------for Quantization_Quality = 0:1 % 0 -> coarse quantization.'jpeg' ) ).43 - .3.2)) reverse_zigzag_order_8x8(k) = find(ZigZag_Order== k).34 28 29 44 24 47 27 35 22 51 32 40 20 42 15 58 39 48 13 49 8 59 46 55 6 57 16 52 53 62 7 50 23 45 60 63 14 43 30 38 61 56 21 36 37 31 54 64]). imshow(input_image_128x128).1}.1). %-----------------------------------------------------------------close all.

x) = 1.* selection_matrix_128x128.16.x] = find(dct_coefficient_priority_8x8==min(min(dct_coefficient_priority_8x8))) % select specific coefficients by location index y.2).* selection_matrix_128x128. % title( sprintf('8x8 DCT of image #%d'. % start mark for elapsed time for encoding & decoding %------------------------. % imshow(dct_transformed_image).Forward DCT ------------------------------% for each picture perform a 2 dimensional dct on 8x8 blocks. %--------------------------------------------------------------------%normalize dct_transformed_image by the maximum coefficient value in dct_transformed_image Maximum_Value_of_dct_coeffieient = max(max(dct_transformed_image)). if DCT_type==0 dct_transformed_image = Classic_DCT(input_image_128x128) . % set it as 99 for the chosen dct coefficient.16 ).show the DCT of image -----------------------------% one can use this portion to show DCT coefficients of the image % subplot(2.% this loop will choose 1 dct coefficients each time for l=1:chosen_number_of_dct_coefficient % find the most energetic coefficient from the mean_matrix [y. end % replicate the selection matrix for all the parts of the dct transform selection_matrix_128x128 = repmat( coef_selection_matrix_8x8. so that in the next loop. end %--------------------------------------------------------------------%---------------. %--------------------------------------------------------------------tic . else dct_transformed_image = image_8x8_block_flowgraph_forward_dct(input_image_128x128) ./Maximum_Value_of_dct_coeffieient. %-------------------. %integer conversion of dct_transformed_image dct_transformed_image_int = im2uint8( dct_transformed_image ).Quantization ----------------------------------% replicate the 'Q_8x8' for at a time whole (128x128) image quantization .44 - .Image_Index) ).2. dct_transformed_image = dct_transformed_image.x) = 99. we will choose the "next-most-energetic" coefficient dct_coefficient_priority_8x8(y.x for the image to be compressed coef_selection_matrix_8x8(y.

% index array of next non-zero entry in a block number_of_non_zero_entries = length(non_zero_value_index_array). run. %for coarse quantization else quantization_matrix_128x128 = repmat(uint8(ceil(double(Q_8x8). [8 8]. %for fine quantization end %at a time whole image (128x128) quantization quantized_image_128x128 = round(dct_transformed_image_int . for Temp_Vector_Index=1:64 single_block_image_vector_64(Temp_Vector_Index) = ZigZaged_Single_Column_Image(Temp_Vector_Index./40)).16.Run Level Coding ----------------------------% construct Run Level Pair from ZigZaged_Single_Column_Image run_level_pairs=uint8([]).45 - .if Quantization_Quality==0 quantization_matrix_128x128 = repmat(Q_8x8.16 ).16 ). single_block_image_vector_64(non_zero_value_index_array(1))).run_level_pairs.'distinct'). % no leading zero run_level_pairs=cat(1. block_index). end % Case 2: loop through each non-zero entry for n=2:number_of_non_zero_entries.total 256 blocks (8x8) in the 128x128 image single_block_image_vector_64(1:64)=0.zigzag ---------------------------------% using the MatLab Matrix indexing power (specially the ':' operator) rather than any function ZigZaged_Single_Column_Image=Single_column_quantized_image(ZigZag_Order. for block_index=1:256 %block by block . %select 1 block sequentially from the ZigZaged_Single_Column_Image end non_zero_value_index_array = find(single_block_image_vector_64~=0). %--------------------------. run=0.16.: )./quantization_matrix_128x128) . %--------------------------------------------------------------------%---------------------. % check # of leading zeros (run) run=non_zero_value_index_array(n)-non_zero_value_index_array(n1)-1. % # of non-zero entries in a block % Case 1: if first ac coefficient has no leading zeros then encode first coefficient if non_zero_value_index_array(1)==1. . %round operation should be done here for lossy quantization %--------------------------------------------------------------------% Break 8x8 block into columns Single_column_quantized_image=im2col(quantized_image_128x128.

0). for n=1:2:size(run_level_pairs). % concatenate single'level' i. a non zero value % Case 3: End of Block decoding else number_of_trailing_zeros= 64-mod(size(c). % file size after compression Compression_Ratio = 20480/Compressed_image_size(1.c.c. 255). run_level_pairs. run_level_pairs. end end end %--------------------------------------------------------------------%--------------------------------------------------------------------% prepare the ZigZaged_Single_Column_Image vector (each column represents 1 block) from the % intermediate concatenated vector "c" for i=1:256 .. single_block_image_vector_64(non_zero_value_index_array(n))).1). % loop through run_level_pairs % Case 1 & Cae 2 % concatenate zeros according to 'run' value if run_level_pairs(n)<255 % only end of block should have 255 value zero_count=0. for l= 1:number_of_trailing_zeros % concatenate as much zeros as needed to fill a block c=cat(1. for l=1:zero_count % concatenation of zeros accouring to zero_count c=cat(1.64).run_level_pairs(n+1)). end % Case 3: "End of Block" mark insertion run_level_pairs=cat(1.0).e. % % % % % % % % % % % % % % % ------------------------------------------------------------------------------------------------------------------------------------DECODING ------------------------------------------------------------------------------------------------------------------------------------- %---------------------. run.46 - .run_level_pairs=cat(1. end %--------------------------------------------------------------------Compressed_image_size=size(run_level_pairs). zero_count=run_level_pairs(n).Run Level Decoding --------------------------% construct ZigZaged_Single_Column_Image from Run Level Pair c=[].c. 255. % single zero concatenation end c=cat(1.

reverse zigzag -------------------------%reverse zigzag procedure using the matrix indexing capability of MatLab (specially the ':' operator) Single_column_quantized_image = ZigZaged_Single_Column_Image(reverse_zigzag_order_8x8. end [8 8]. if DCT_type == 0 if Quantization_Quality == 0 title( sprintf('coarse quantize\nClassic DCT\nRestored image with %d coeffs\nCompression ratio %. %--------------------------------------------------------------------%image matrix construction from image column quantized_image_128x128 = col2im(Single_column_quantized_image.chosen_number_of_dct_coefficient.Compression_Ratio.47 - .Show restored image ---------------------subplot(3.3.2f\nTime %f'. %Maximum_Value_of_dct_coeffieient is used for reverse nornalization end %--------------------------------------------------------------------elapsed_time = toc.elapsed_time) ).*Maxi mum_Value_of_dct_coeffieient ).i)=c(64*(i-1)+j). imshow( restored_image ).deQuantization --------------------------------dct_transformed_image = quantized_image_128x128.Inverse DCT -----------------------------% restore the compressed image from the given set of coeficients if DCT_type==0 restored_image = image_8x8_block_inv_dct( im2double(dct_transformed_image). %--------------------------------------------------------------------%-------------------------.end %--------------------------------------------------------------------%--------------------------. [128 128]. 'distinct').:). %Maximum_Value_of_dct_coeffieient is used for reverse nornalization else restored_image = image_8x8_block_flowgraph_inverse_dct( im2double(dct_transformed_image). %-------------------.*quantization_matrix_128x128 . Quantization_Quality*2^2+ DCT_type*2+ floor(chosen_number_of_dct_coefficient/64)+2). for j=1:64 ZigZaged_Single_Column_Image(j. % time required for both enconing & decoding %-------------------------. else .*Maximum_Value_of_d ct_coeffieient ).

48 - .Compression_Ratio.elapsed_time) ).1). end else if Quantization_Quality == 0 title( sprintf('coarse quantize\nFast DCT\nRestored image with %d coeffs\nCompression ratio %.n+1) = cos(pi*(2*n+1)*k/2/N)/sqrt(N).chosen_number_of_dct_coefficient. else C(k+1.Compression_Ratio.implementation of an inverse 2 Dimensional DCT % assumption: input matrix is a square matrix ! % -----------------------------------------------------------------------function out = pdip_inv_dct2( in ) . else title( sprintf('fine quantize\nFast DCT\nRestored image with %d coeffs\nCompression ratio %.n+1) = cos(pi*(2*n+1)*k/2/N)/sqrt(N)*sqrt(2).2f\nTime %f'.implementation of a 2 Dimensional DCT % assumption: input matrix is a square matrix ! % -----------------------------------------------------------------------function out = Classic_DCT_Block_8x8( in ) % get input matrix size N = size(in.2f\nTime %f'. end end %--------------------------------------------------------------------end end end % % % % end end of coefficient number loop end of DCT type loop end of quantization qualoty loop of image index loop end end % end of 'jpeg' function %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% I N N E R F U N C T I O N I M P L E M E N T A T I O N %% ----------------------------------------------------------------------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -----------------------------------------------------------------------% Classic_DCT_Block_8x8 . for k = 0:N-1 if (k>0) C(k+1.2f\nTime %f'.chosen_number_of_dct_coefficient. end % end of Classic_DCT_Block_8x8 function % -----------------------------------------------------------------------% pdip_inv_dct2 . end end out = C*in*(C'). % build the matrix n = 0:N-1.elapsed_time) ).elapsed_time) ).Compression_Ratio.chosen_number_of_dct_coefficient.title( sprintf('fine quantize\nclassic DCT\nRestored image with %d coeffs\nCompression ratio %.

for m = 0:15 for n = 0:15 transform_image( m*8+[1:8]. end end out = (C')*in*C.1 ).n*8+[1:8] ) = Classic_DCT_Block_8x8( input_image( m*8+[1:8].size( transform_image.49 - . for m = 0:15 for n = 0:15 transform_image( m*8+[1:8].size( input_image.2 ) ). else C(k+1.perform a block Flowgraph forward DCT for an image % -----------------------------------------------------------------------function transform_image = image_8x8_block_flowgraph_forward_dct( input_image ) transform_image = zeros( size( input_image.2 ) ).1 ).size( input_image.n*8+[1:8] ) ).n+1) = cos(pi*(2*n+1)*k/2/N)/sqrt(N)*sqrt(2). end end end % -----------------------------------------------------------------------% image_8x8_block_inv_dct . end end end % -----------------------------------------------------------------------% image_8x8_block_flowgraph_forward_dct .perform a block inverse DCT for an image % -----------------------------------------------------------------------function restored_image = image_8x8_block_inv_dct( transform_image ) restored_image = zeros( size( transform_image.n+1) = cos(pi*(2*n+1)*k/2/N)/sqrt(N).n*8+[1:8] ) = flowgraph_forward_dct( input_image( m*8+[1:8].1 ).perform a block DCT for an image % -----------------------------------------------------------------------function transform_image = Classic_DCT( input_image ) transform_image = zeros( size( input_image. for k = 0:N-1 if (k>0) C(k+1. end % -----------------------------------------------------------------------% Classic_DCT .1). for m = 0:15 for n = 0:15 .% get input matrix size N = size(in.n*8+[1:8] ) ).2 ) ). % build the matrix n = 0:N-1.

8).size( transform_image.382683.923880.n*8+[1:8] ) = pdip_inv_dct2( transform_image( m*8+[1:8]. i2=f2+f5. c3=0.n*8+[1:8] ) = flowgraph_inverse_dct( transform_image( m*8+[1:8].50 - .2 ) ).3). c4=0. f6=in_8x8(row_number.1 ).831470. %---------------------------row calculation FDCT-------------------------for row_number=1:8 %sample image value initialization from input matrix f0=in_8x8(row_number. f3=in_8x8(row_number. f4=in_8x8(row_number.1). c2=0.707107. end end end % -----------------------------------------------------------------------% image_8x8_block_flowgraph_inverse_dct . f7=in_8x8(row_number. i1=f1+f6.6). c6=0. f5=in_8x8(row_number. c5=0.4).n*8+[1:8] ) ).n*8+[1:8] ) ).perform a block Flowgraph inverse DCT for an image % -----------------------------------------------------------------------function restored_image = image_8x8_block_flowgraph_inverse_dct( transform_image ) restored_image = zeros( size( transform_image.Fralick and Smith) % -----------------------------------------------------------------------function [DCT_8x8] = flowgraph_forward_dct(in_8x8) % constant cosine values will be used for both forward & inverse flowgraph DCT c1=0.2). end end end % -----------------------------------------------------------------------% FLOWGRAPH forward dct (Chen. %first stage of FLOWGRAPH (Chen. f2=in_8x8(row_number.5).restored_image( m*8+[1:8].980785.555570. f1=in_8x8(row_number. i3=f3+f4.195090.Fralick and Smith) i0=f0+f7.7). for m = 0:15 for n = 0:15 restored_image( m*8+[1:8]. . c7=0.

%third stage of FLOWGRAPH (Chen. F7=(k7*c7-k4*c1)/2. One_D_DCT_Row_8x8(row_number. i5=f2-f5. 1-dimensional DCT coefficients F0=k0/2. k7=j7+j6.2)=F1. k1=(j0-j1)*c4.Fralick and Smith) j0=i0+i3.4)=F3. One_D_DCT_Row_8x8(row_number. %second stage of FLOWGRAPH (Chen. . %fourth stage of FLOWGRAPH. j1=i1+i2. j5=(i6-i5)*c4. One_D_DCT_Row_8x8(row_number. One_D_DCT_Row_8x8(row_number. j3=i0-i3. One_D_DCT_Row_8x8(row_number. i6=f1-f6. k2=(j2*c6)+(j3*c2). k4=j4+j5. F4=k1/2.Fralick and Smith) k0=(j0+j1)*c4. k6=j7-j6.i4=f3-f4.column_number). F1=(k4*c7+k7*c1)/2. F5=(k5*c3+k6*c5)/2. One_D_DCT_Row_8x8(row_number.column_number). One_D_DCT_Row_8x8(row_number. j2=i1-i2. F2=k2/2.6)=F5. end %end of row calculations %---------------------------end: row calculation FDCT--------------------%--------------------------. f1=One_D_DCT_Row_8x8(2. i7=f0-f7.7)=F6.51 - . F3=(k6*c3-k5*c5)/2. f2=One_D_DCT_Row_8x8(3. j7=i7. f3=One_D_DCT_Row_8x8(4.3)=F2.column calculation FDCT---------------------for column_number=1:8 %start of column calculation %sample image value initialization f0=One_D_DCT_Row_8x8(1.5)=F4.8)=F7.1)=F0. k5=j4-j5. j6=(i6+i5)*c4. %DCT coefficient assignment One_D_DCT_Row_8x8(row_number.column_number). j4=i4.column_number). F6=k3/2. k3=(j3*c6)-(j2*c2).

i6=f1-f6. i3=f3+f4. DCT_8x8(4. Desired DCT coefficients F0=k0/2.column_number)=F7. F4=k1/2.column_number).column_number)=F6. %third stage of FLOWGRAPH (Chen.column_number).column_number)=F3. f7=One_D_DCT_Row_8x8(8. k3=(j3*c6)-(j2*c2). %first stage of FLOWGRAPH (Chen. F2=k2/2. %second stage of FLOWGRAPH (Chen. k1=(j0-j1)*c4. j4=i4. DCT_8x8(7. %DCT coefficient assignment DCT_8x8(1. k6=j7-j6. j1=i1+i2.column_number)=F1. DCT_8x8(6.column_number)=F4. j6=(i6+i5)*c4.Fralick and Smith) i0=f0+f7. j2=i1-i2.f4=One_D_DCT_Row_8x8(5. k7=j7+j6. k4=j4+j5. j7=i7. f6=One_D_DCT_Row_8x8(7. j5=(i6-i5)*c4. i7=f0-f7.column_number). j3=i0-i3.column_number)=F2. i4=f3-f4. DCT_8x8(5. DCT_8x8(3. DCT_8x8(8. i2=f2+f5. i1=f1+f6.column_number)=F0. k2=(j2*c6)+(j3*c2). end %end of column calculations %---------------------------end: column calculation FDCT------------------ .Fralick and Smith) j0=i0+i3. DCT_8x8(2.column_number). F1=(k4*c7+k7*c1)/2. f5=One_D_DCT_Row_8x8(6.52 - .Fralick and Smith) k0=(j0+j1)*c4. %fourth stage of FLOWGRAPH.column_number)=F5. F7=(k7*c7-k4*c1)/2. i5=f2-f5. F6=k3/2. k5=j4-j5. F5=(k5*c3+k6*c5)/2. F3=(k6*c3-k5*c5)/2.

j2=(k2*c6-k3*c2). % second stage of FLOWGRAPH (Chen. j4=k4+k5. F7=DCT_8x8(row_number.6).53 - . c6=0. F4=DCT_8x8(row_number. k4=(F1/2*c7-F7/2*c1).980785.4). %---------------------------row calculation Inverse DCT------------------for row_number=1:8 %DCT coefficient initialization F0=DCT_8x8(row_number. c7=0.end % end of function flowgraph_forward_dct % -----------------------------------------------------------------------% FLOWGRAPH Inverse dct (Chen.7). j7=k7+k6. k6=F5/2*c5+F3/2*c3.Fralick and Smith) k0=F0/2. k7=F1/2*c1+F7/2*c7.2). k2=F2/2. c2=0. F3=DCT_8x8(row_number.831470. % third stage of FLOWGRAPH (Chen.3). F1=DCT_8x8(row_number.382683.Fralick and Smith) % -----------------------------------------------------------------------function [out_8x8] = flowgraph_inverse_dct(DCT_8x8) % constant cosine values will be used for both forward & inverse flowgraph DCT c1=0. .Fralick and Smith) i0=j0+j3.8). i1=j1+j2.5). k1=F4/2. c4=0.Fralick and Smith) j0=(k0+k1)*c4. k3=F6/2. k5=(F5/2*c3-F3/2*c5). j5=(k4-k5).923880. j1=(k0-k1)*c4. c3=0.1). i2=(j1-j2). j6=(k7-k6). % first stage of FLOWGRAPH (Chen. F6=DCT_8x8(row_number. c5=0.707107. F5=DCT_8x8(row_number.555570. F2=DCT_8x8(row_number.195090. j3=k2*c2+k3*c6.

%1 dimensional sample image vale assignment only after row calculations One_D_IDCT_Row_8x8(row_number. % fourth stage of FLOWGRAPH (Chen. f2=i2+i5. k3=F6/2.Fralick and Smith) f0=i0+i7. f4=(i3-i4).8)=f7. F4=One_D_IDCT_Row_8x8(5. end %---------------------------end: row calculation Inverse DCT-------------%---------------------------column calculation Inverse DCT---------------for column_number=1:8 %DCT coefficient initialization F0=One_D_IDCT_Row_8x8(1. f6=(i1-i6). % second stage of FLOWGRAPH (Chen. i5=(j6-j5)*c4. i4=j4. F1=One_D_IDCT_Row_8x8(2.column_number). i6=(j5+j6)*c4.4)=f3. One_D_IDCT_Row_8x8(row_number.column_number).7)=f6.5)=f4. .1)=f0. F6=One_D_IDCT_Row_8x8(7. k6=F5/2*c5+F3/2*c3.54 - .i3=(j0-j3). One_D_IDCT_Row_8x8(row_number.Fralick and Smith) k0=F0/2. i7=j7. F2=One_D_IDCT_Row_8x8(3. j1=(k0-k1)*c4. k1=F4/2. f3=i3+i4. j2=(k2*c6-k3*c2). k2=F2/2. f7=(i0-i7).6)=f5. F7=One_D_IDCT_Row_8x8(8. F3=One_D_IDCT_Row_8x8(4. One_D_IDCT_Row_8x8(row_number. f1=i1+i6.column_number). One_D_IDCT_Row_8x8(row_number.column_number).Fralick and Smith) j0=(k0+k1)*c4.column_number). One_D_IDCT_Row_8x8(row_number.column_number). f5=(i2-i5). k5=(F5/2*c3-F3/2*c5). One_D_IDCT_Row_8x8(row_number. One_D_IDCT_Row_8x8(row_number.column_number). k4=(F1/2*c7-F7/2*c1). k7=F1/2*c1+F7/2*c7.2)=f1.3)=f2.column_number). % first stage of FLOWGRAPH (Chen. F5=One_D_IDCT_Row_8x8(6.

i3=(j0-j3). j7=k7+k6.column_number)=f2.Fralick and Smith) f0=i0+i7. out_8x8(3. i6=(j5+j6)*c4. out_8x8(8. out_8x8(6. f7=(i0-i7). i1=j1+j2. f4=(i3-i4). out_8x8(4.column_number)=f7. j4=k4+k5. i5=(j6-j5)*c4.column_number)=f1. f5=(i2-i5). out_8x8(7. i7=j7.column_number)=f3. f3=i3+i4. i4=j4.55 - . i2=(j1-j2). % Desired sample image values assignment only after 2 dimensional inverse transformation out_8x8(1. f1=i1+i6. % fourth stage of FLOWGRAPH (Chen.column_number)=f5. out_8x8(2. out_8x8(5.Fralick and Smith) i0=j0+j3. end %---------------------------end: column calculation Inverse DCT----------end % end of function flowgraph_inverse_dct ------------------------------------**************************-----------------------------------------------------------------------------**************************----------------------------------------- .column_number)=f6.column_number)=f4. % third stage of FLOWGRAPH (Chen. f6=(i1-i6). j5=(k4-k5). f2=i2+i5.j3=k2*c2+k3*c6. j6=(k7-k6).column_number)=f0.