You are on page 1of 24

A

Project Report

On

IMAGE COMPRESSION USING DISCRETE COSINE TRANSFORM IN MATLAB

Submitted to

CHHATTISGARH SWAMI VIVEKANAND TECHNICAL UNIVERSITY

BHILAI

in partial fulfillment of requirement for the award of degree

of

Bachelor of Engineering

In

Electronics & Telecommunication Engineering

By

NEERAJ SHRIVASTAVA

RUPESH GUPTA

SAHIL ASATI

SATISH RAJPUT

Department of Electronics & Telecommunication Engineering

Chhatrapati Shivaji Institute of Technology, Durg

Shivaji Nagar, Balod Road, Kolihapuri, Post Pisegaon – Durg (C.G.) 491001

Session : 2009 - 2010


DECLARATION

I the undersigned solemnly declare that the report of the project work entitled “IMAGE
COMPRESSION USING DISCRETE COSINE TRANSFORM IN MATLAB” , is based my
own work carried out during the course of my study under the supervision of Mr. O.P. YADAV.

I assert that the statements made and conclusions drawn are an outcome of the project
work. I further declare that to the best of my knowledge and belief that the report does not contain
any part of any work which has been submitted for the award of any other
degree/diploma/certificate in this University of any other University.

(Signature of the Candidate)


Name of the Candidate: SAHIL ASATI
Roll No. : 3032806095
Enrollment No.: AA8837
CERTIFICATE

This is to certify that the report of the project submitted is an outcome of the project work entitled
“IMAGE COMPRESSION USING DISCRETE COSINE TRANSFORM IN MATLAB”
carried out by SAHIL ASATI bearing Roll No.: 3032806095 & Enrollment No. :AA8837Carried
out under my guidance and supervision for the award of Degree in Bachelor of Engineering in
ELECTRONICS & TELECOMMUNICATION of Chhattisgarh Swami Vivekanand Technical
University, Bhilai (C.G.), India.

To the best of my knowledge the report

i) Embodies the work of the candidate him/herself,

ii) Has duly been completed,

iii) Fulfils the requirement of the Ordinance relating to the BE degree of the University and

iv) Is up to the desired standard for the purpose of which is submitted.

(Signature of the Guide)


Mr. O.P.YADAV
Sr. Lecturer
ELECTRONICS & TELECOMMUNICATION
CHHATRAPATI SHIVAJ ISTITUTE OF TECHNOLOGY DURG(C.G.)

The project work as mentioned above is hereby being recommended and forwarded for
examination and evaluation.

(Signature of Head of the department with seal)


CERTIFICATE BY THE EXAMINERS

This is to certify that the project work entitled

“IMAGE COMPRESSION USING DISCRETE COSINE TRANSFORM IN MATLAB”

Submitted by

NEERAJ SHRIVASTAVA Roll No. : 3032806071 Enrollment No. : AA8777

RUPESH GUPTA Roll No. : 3032806094 Enrollment No. : AA8835

SAHIL ASATI Roll No. : 3032806095 Enrollment No. : AA8837

SATISH RAJPUT Roll No. : 3032806098 Enrollment No. : AA8843

been examined by the undersigned as a part of the examination for the award of Bachelor of
Engineering degree in Electronics & Telecommunication Engineering of Chhattisgarh Swami
Vivekanand Technical University, Bhilai.

Internal Examiner External Examiner

Date: Date:
ACKNOWLEDGEMENT

A completion with project has been a source of great practical experience and personal pride for us
and we take this opportunity to thank all those who have been us in our indeavor.

We wish to acknowledge our profound sense of gratitude to our project guide Mr.O.P. YADAV
for always providing us the much needed help to vast array of knowledge.we give the heart soul
thanks to our guide for always being there for us.

We extend our thanks to respected Mr.AJAY PRAKASH VERMA(chairmain) for these support
encouragement and facilitation.we are also greateful to (principal) and Mr.MANGAL SINGH
(H.O.D.) for their valuable guidance that they shared with us through there project.

(Signature of the Student) (Signature of the Student)


Name : NEERAJ SRIVASTAVA Name :RUPESH GUPTA

(Signature of the Student) (Signature of the Student)


Name :SAHIL ASATI Name SATISH RAJPUT

CHHATRAPATI SHIVAJI INSTITUTE OF TECHNOLOGY, DURG

Shivaji Nagar, Balod Road, Kolihapuri, Post Pisegaon – Durg (C.G.) 491001
Table of Contents(Font size-16)

Chapter Title Page No.

I Introduction 1
1.1 Image Processing
1.1.1 Binarization
1.1.2 Segmetation
1.1.3 Method of segmentation
1.1.3.1 Clustering method
1.1.3.2 Histogram method
1.1.3.3 Edge detection
1.1.3.4 Region growing method

1.2 Discrete cosine transform


1.2.1 Description
1.2.2 What is DCT
1.2.3 Mathematical Analysis
1.2.4 Classification
1.2.5 Utility
1.2.6 Advantages

1.3 Image compression


1.3.1 History
1.3.2 Description
1.3.3 Principle of image compression
1.3.4 Types of image compression
1.3.4.1 Lossless compression
1.3.4.2 Lossy compression
1.3.5 Compression techniques
1.3.5.1 Discrete cosine transform
1.3.5.1.1 Joint Photographic Expert Group
1.3.5.1.2 Motion Picture Expert Group
1.3.5.2 Fractal compression
1.3.5.3 Wavelet Transform
1.3.5.3.1 Continuous wavelet transform
1.3.5.3.2 Discrete wavelet transform

II Literature Review
2.1 Sub article X
2.1.1 Sub-Sub article

III Problem Identification


3.1 Sub article Y
3.1.1 Sub-Sub article
IV Methodology
4.1 Sub article Z
4.1.1 Sub-Sub article
V Results & Discussions
5.1 Sub article P
5.1.1 Sub-Sub article
VI Conclusion & Scope of further work
6.1 Sub article Q
6.1.1 Sub-Sub article
VII Bibliography T

Appendix
List of Tables

S.No. Table Table No.


List of Figures

S.No. Figuree Figure No.


Chapter – I

Introduction
(Font size-36)
introduction
Compressing an image is significantly different than compressing raw binary data. Of course,
general purpose compression programs can be used to compress images, but the result is less than
optimal. DCT has been widely used in signal processing of image. The one-dimensional DCT is
useful in processing one-dimensional signals such as speech waveforms. For analysis of
twodimensional(2D) signals such as images, we need a 2D version of the DCT data, especially in
coding for compression, for its near-optimal performance. JPEG is a commonly used standard
method of compression for photographic images. The name JPEG stands for Joint Photographic
Experts Group, the name of the committee who created the standard. JPEG provides for lossy
compression of images.
Image compression is the application of data compression on digital images. In effect, the
objective is to reduce redundancy of the image data in order to be able to store or transmit data in
an efficient form. The best image quality at a given bit-rate (or comprweession rate) is the main
goal of image compression. The main objectives of this paper are Reducing the image storage
space, Easymaintenance and providing security, Data loss cannot effect the image clarity, Lower
bandwidth\requirements for transmission, Reducing cost.

What is dct

A discrete cosine transform (DCT) expresses a sequence of finitely many data points in terms of a
sum of cosine functions oscillating at different frequencies. DCTs are important to numerous
applications in science and engineering, from lossy compression of audio and images (where
small high-frequency components can be discarded), to spectral methods for the numerical
solution of partial differential equations on, it turns out that cosine functions are much more
efficient (as explained below, fewer are needed to approximate a typical signal, whereas for
differential equations the cosines express a particular choice of boundary conditions.

In particular, a DCT is a Fourier-related transform similar to the discrete Fourier transform (DFT),
but using only real numbers. DCTs are equivalent to DFTs of roughly twice the length, operating
on real data with even symmetry (since the Fourier transform of a real and even function is real
and even), where in some variants the input and/or output data are shifted by half a sample. There
are eight standard DCT variants, of which four are common.

The most common variant of discrete cosine transform is the type-II DCT, which is often called
simply "the DCT"; its inverse, the type-III DCT, is correspondingly often called simply "the
inverse DCT" or "the IDCT". Two related transforms are the discrete sine transform (DST), which
is equivalent to a DFT of real and odd functions, and the modified discrete cosine transform
(MDCT), which is based on a DCT of overlapping data.

Types of dct

DCT-I
The DCT-I is exactly equivalent (up to an overall scale factor of 2), to a DFT of 2N − 2 real
numbers with even symmetry. For example, a DCT-I of N=5 real numbers abcde is exactly
equivalent to a DFT of eight real numbers abcdedcb (even symmetry), divided by two. (In contrast,
DCT types II-IV involve a half-sample shift in the equivalent DFT.)

Note, however, that the DCT-I is not defined for N less than 2. (All other DCT types are defined
for any positive N.)

Thus, the DCT-I corresponds to the boundary conditions: xn is even around n=0 and even around
n=N-1; similarly for Xk

Some authors further multiply the x0 and xN-1 terms by √2, and correspondingly multiply the X0 and
XN-1 terms by 1/√2. This makes the DCT-I matrix orthogonal, if one further multiplies by an overall

scale factor of , but breaks the direct correspondence with a real-even DFT.

The DCT-I is exactly equivalent (up to an overall scale factor of 2), to a DFT of 2N − 2 real
numbers with even symmetry. For example, a DCT-I of N=5 real numbers abcde is exactly
equivalent to a DFT of eight real numbers abcdedcb (even symmetry), divided by two. (In contrast,
DCT types II-IV involve a half-sample shift in the equivalent DFT.)

Note, however, that the DCT-I is not defined for N less than 2. (All other DCT types are defined
for any positive N.)

Thus, the DCT-I corresponds to the boundary conditions: xn is even around n=0 and even around
n=N-1; similarly for Xk.

DCT-II

The DCT-II is probably the most commonly used form, and is often simply referred to as "the
DCT".

This transform is exactly equivalent (up to an overall scale factor of 2) to a DFT of 4N real inputs
of even symmetry where the even-indexed elements are zero. That is, it is half of the DFT of the
4N inputs yn, where y2n = 0, y2n + 1 = xn for , and y4N − n = yn for 0 < n < 2N.

Some authors further multiply the X0 term by 1/√2 and multiply the resulting matrix by an overall

scale factor of (see below for the corresponding change in DCT-III). This makes the DCT-
II matrix orthogonal, but breaks the direct correspondence with a real-even DFT of half-shifted
input.

The DCT-II implies the boundary conditions: xn is even around n=-1/2 and even around n=N-1/2;
Xk is even around k=0 and odd around k=N.

DCT-III
Because it is the inverse of DCT-II (up to a scale factor, see below), this form is sometimes simply
referred to as "the inverse DCT" ("IDCT").

Some authors further multiply the x0 term by √2 and multiply the resulting matrix by an overall

scale factor of (see above for the corresponding change in DCT-II), so that the DCT-II and
DCT-III are transposes of one another. This makes the DCT-III matrix orthogonal, but breaks the
direct correspondence with a real-even DFT of half-shifted output.

The DCT-III implies the boundary conditions: xn is even around n=0 and odd around n=N; Xk is
even around k=-1/2 and even around k=N-1/2.

[edit] DCT-IV

The DCT-IV matrix becomes orthogonal (and thus, being clearly symmetric, its own inverse) if

one further multiplies by an overall scale factor of .

A variant of the DCT-IV, where data from different transforms are overlapped, is called the
modified discrete cosine transform (MDCT) (Malvar, 1992).

The DCT-IV implies the boundary conditions: xn is even around n=-1/2 and odd around n=N-1/2;
similarly for Xk.

[edit] DCT V-VIII

DCT types I-IV are equivalent to real-even DFTs of even order (regardless of whether N is even or
odd), since the corresponding DFT is of length 2(N−1) (for DCT-I) or 4N (for DCT-II/III) or 8N
(for DCT-VIII). In principle, there are actually four additional types of discrete cosine transform
(Martucci, 1994), corresponding essentially to real-even DFTs of logically odd order, which have
factors of N±½ in the denominators of the cosine arguments.

Equivalently, DCTs of types I-IV imply boundaries that are even/odd around either a data point for
both boundaries or halfway between two data points for both boundaries. DCTs of types V-VIII
imply boundaries that even/odd around a data point for one boundary and halfway between two
data points for the other boundary.

However, these variants seem to be rarely used in practice. One reason, perhaps, is that FFT
algorithms for odd-length DFTs are generally more complicated than FFT algorithms for even-
length DFTs (e.g. the simplest radix-2 algorithms are only for even lengths), and this increased
intricacy carries over to the DCTs as described below.

(The trivial real-even array, a length-one DFT (odd length) of a single number a, corresponds to a
DCT-V of length N=1.)

Advantages
1. DCT transform is a pretty good technique for image compression. Correctly use the
advantage that provide by DCT is the key to achieve good result while keep a good
compression ratio.

2. The small size DCT is suitable for mobile applications using low power devices as fast
computation speed is required for real time applications.

3. Low complexity, and high fidelity image compression using fixed threshold method

4.DCT is real-valued and provides a better approximation of a signal with fewer coefficients.

5. DCT namely simplicity, satisfactory performance, and availability of special purpose hardware
for implementation,

6. The DCT is a widely used transformation in transformation for data compression. It is an


orthogonal transform, which has a fixed set of (image independent) basis functions, an efficient
algorithm for computation, and good energy compaction and correlation reduction properties.
7. The DCT is fast. It can be quickly calculated and is best for images with smooth edges like
photos with human subjects.
8. DCT algorithms are capable of achieving a high degree of compression with only minimal loss
of data. This scheme is effective only for compressing continuous-tone images in which the
differences between adjacent pixels are usually small.
9. studies have shown that DCT provides better energy compaction than DFT for most natural
images.
9. The decorrelation characteristics of DCT should render a decrease in the entropy (or
selfinformation) of an image. This will, in turn, decrease the number of bits required to represent
the image.

Disadvantages of dct

1.Only spatial correlation of the pixels inside the single 2-D block is considered and the
correlation from the pixels of the neighboring blocks is neglected

2.Impossible to completely decorrelate the blocks at their boundaries using DCT

3.Undesirable blocking artifacts affect the reconstructed images or video frames. (high
compression ratios or very low bit rates)

4. Since the input image needs to be ``blocked,'' correlation across the block boundaries is not
eliminated. This results in noticeable and annoying ``blocking artifacts'' particularly at low bit rates

5. At compression ratios above 30:1, JPEG performance rapidly deteriorates, while wavelet coders
degrade gracefully well beyond ratios of 100:1. at higher compression ratios, image quality
degrades because of the artifacts resulting from the block-based DCT scheme.
6. Frequently changing colors in dense spaces cannot be represented well with few coefficients.
For example, a row of pixels interchanging between black and white pixel-by-pixel, is viewed as a
high frequency in the frequency domain. However, a high frequency cannot be represented with
few coefficients, and thus dropping high-order coefficients from the DCT removes the necessary
detail. This is also the reason why diagrams are not compressed using jpeg compression.
7. DCT-based encoding algorithms are always lossy by nature.
8. Removal of high-frequency coefficients results in removal of
certain frequencies that were originally present in the sine wave. After losing certain frequencies
it is not possible to achieve perfect reconstruction
5.DCT function is fixedàcan not be adapted to source data

6.Does not perform efficiently for binary images (fax or pictures of fingerprints) characterized by
large periods of constant amplitude (low spatial frequencies), followed by brief periods of sharp
transitions

7.At compression ratios above 30:1, JPEG performance rapidly deteriorates, while wavelet coders
degrade gracefully well beyond ratios of 100:1. at higher compression ratios, image quality
degrades because of the artifacts resulting from the block-based DCT scheme.

8. Ringing is a major problem in DCT operation. When edges occur in an image DCT
relies on the high frequency components to make the image shaper. However these high frequency
components persist across the whole block and although they are effective at improving the edge
quality they tend to 'ring' in the flat areas of the block.

Dct equation

The DCT equation (Eq.1) computes the i, jth entry of the DCT of an image.

p (x, y) is the x,yth element of the image represented by the matrix p. N is the size of the block that
the DCT is done on. The equation calculates one entry (i, j th) of the transformed image from the
pixel values of the original image matrix. For the standard 8x8 block that JPEG compression uses,
N equals 8 and x and y range from 0 to 7. Therefore D (i, j ) would be as in Equation (3).

Because the DCT uses cosine functions, the resulting matrix depends on the horizontal and vertical
frequencies. Therefore an image black with a lot of change in frequency has a very random looking
resulting matrix, while an image matrix of just one color, has a resulting matrix of a large value for
the first element and zeroes for the other.

THE DCT MATRIX:

To get the matrix form of Equation (1), we will use the following equation,
For an 8x8 block it results in this matrix:

The first row (i : 1) of the matrix has all the entries equal to 1/ 8 as expected from Equation (4).The
columns of T form an orthonormal set, so T is an orthogonal matrix. When doing the inverse DCT
the orthogonality of T is important, as the inverse of T is T’ which is easy to calculate.

PROPERTIES OF DCT:
Some properties of the DCT which are of particular value to image processing applications:
a) Decorrelation: The principle advantage of image transformation is the removal of redundancy
between neighboring pixels. This leads to uncorrelated transform coefficients which can be
encoded independently. It can be inferred that DCT exhibits excellent decorrelation properties.
b) Energy Compaction: Efficacy of a transformation scheme can be directly gauged by its ability
to pack input data into as few coefficients as possible. This allows the quantizer to discard
coefficients with relatively small amplitudes without introducing visual distortion in the
reconstructed image. DCT exhibits excellent energy compaction for highly correlated images.
c) Separability: The DCT transform equation can be expressed as

This property, known as separability, has the principle advantage that D (i, j) can be computed in
two steps by successive 1-D operations on rows and columns of an image. The arguments
presented can be identically applied for the inverse DCT computation.
d) Symmetry: Another look at the row and column operations in above Equation reveals that these
operations are functionally identical. Such a transformation is called a symmetric transformation.
A separable and symmetric transform can be expressed in the form
D = TMT’
where M is an N ×N symmetric transformation matrix
This is an extremely useful property since it implies that the transformation matrix can be
precomputed offline and then applied to the image thereby providing orders of magnitude
improvement in computation efficiency.

DWT is more general and efficient than DCT due to the following result:-
_ No need to divide the input coding into non-overlapping 2-D blocks, it has higher
compression ratios avoid blocking artifacts.
_ Allows good localization both in time and spatial frequency domain.
_ Transformation of the whole image_ introduces inherent scaling
_ Better identification of which data is relevant to human perception_ higher
compression ratio

Applications of dct

1.The DCT, and in particular the DCT-II, is often used in signal and image processing, especially
for lossy data compression, because it has a strong "energy compaction" property (Rao and Yip,
1990): most of the signal information tends to be concentrated in a few low-frequency components
of the DCT, approaching the Karhunen-Loève transform (which is optimal in the decorrelation
sense) for signals based on certain limits of Markov processes.

2. A related transform, the modified discrete cosine transform, or MDCT (based on the DCT-IV),
is used in AAC, Vorbis, WMA, and MP3 audio compression.

3.DCTs are also widely employed in solving partial differential equations by spectral methods,
where the different variants of the DCT correspond to slightly different even/odd boundary
conditions at the two ends of the array.

4.DCTs are also closely related to Chebyshev polynomials, and fast DCT algorithms (below) are
used in Chebyshev approximation of arbitrary functions by series of Chebyshev polynomials, for
example in Clenshaw–Curtis quadrature.

5. The DCT is used in JPEG image compression, MJPEG, MPEG, DV, and Theora video
compression.
BIBLIOGRAPHY

Books :

[Sl. No.] <Author>, <”Title of the Book”>, <Name of Publisher>, <Place of Publication>,
<Edition No.>, <year of Publication>, <Chapter No.>, <Page No.>

Periodicals:

[Sl. No.] <Auther/s>, <”Title of research paper”>, <Name of the Journal>, <Vol.>,
<No./Month of publication>, <pp.>, <Year>

Website :

http:www.gobbeldygook.co.uk

Magazines:
1) Everywhere project title should be always Capital/in CAPS LOCK..

2) Now onwards there will be two guides- Guide 1 & Guide 2 in the documentation
whereverequired.

3) Wherever the arrow sign is present, remove the sign & write the same.

4) Bibliography should be of two pages at least & it should not contain the references.

5) All Data sheets are to be there in appendix, it can be further classified like Appendix-I,
Appendix –II and so on.
For any type of Confusion contact me.

Original Image Compression Factor 2

200 200

400 400

600 600
200 400 600 800 200 400 600 800

Compression Factor 4 Compression Factor 8

200 200

400 400

600 600
200 400 600 800 200 400 600 800

Original Image Compression Factor 2 * 2

200 200

400 400

600 600
200 400 600 800 200 400 600 800

Compression Factor 4 * 4 Compression Factor 8 * 8

200 200

400 400

600 600
200 400 600 800 200 400 600 800
Original Image Compression Factor 2

200 200

400 400

600 600
200 400 600 800 200 400 600 800

Compression Factor 4 Compression Factor 8

200 200

400 400

600 600
200 400 600 800 200 400 600 800

Original Image Compression Factor 2 * 2

200 200

400 400

600 600
200 400 600 800 200 400 600 800

Compression Factor 4 * 4 Compression Factor 8 * 8

200 200

400 400

600 600
200 400 600 800 200 400 600 800

Conclusions and Future Directions


DCT(25%) introduces blurring effect in all images since only one-fourth of the total number of
coefficients are utilized for reconstruction. However, DCT(50%) provides almost identical
reconstruction in all images. Nevertheless, DCT(75%) provides excellent reconstruction for all
images except the sine wave.
This is a very interesting result since it suggests that based on the (heterogeneous) bandwidth
requirements of receivers, DCT coefficients can be discarded by the quantizer while rendering
acceptable quality.

The results presented show that the DCT exploits interpixel redundancies to render excellent
decorrelation for most natural images. Thus, all (uncorrelated) transform coefficients can be
encoded independently without compromising coding efficiency. In addition, the DCT packs
energy in the low frequency regions. Therefore, some of the high frequency content can be
discarded without significant quality degradation. Such a (course) quantization scheme causes
further reduction in the entropy (or average number of bits per pixel).

Discrete Cosine Transform (DCT) has emerged as the de-facto image transformation in most
visual systems. DCT has been widely deployed by modern video coding standards, for example,
MPEG, JVT etc. This document introduces the DCT, elaborates its important attributes and
analyzes its performance using information theoretic measures.

The aforementioned attributes of the DCT have led to its widespread deployment in virtually
every image/video processing standard of the last decade, for example, JPEG (classical), MPEG-
1, MPEG-2, MPEG-4, MPEG-4 FGS, H.261, H.263 and JVT (H.26L). Nevertheless, the DCT
still offers new research directions that are being explored in the current and upcoming
image/video coding standards.

The upcoming JPEG-2000 standard will incorporate many of these research works and will
address many important aspects in image coding for the next millennium. However, the current
data compression methods might be far away from the ultimate limits imposed by the underlying
structure of specific data sources such as images. Interesting issues like obtaining accurate models
of images, optimal representations of such models, and rapidly computing such optimal
representations are the "Grand Challenges" facing the data compression community. Interaction of
harmonic analysis with data compression, joint source-channel coding, image coding based on
models of human perception, scalability, robustness, error resilience, and complexity are a few of
the many outstanding challenges in image coding to be fully resolved and may affect image data
compression performance in the years to come.

DWT is more general and efficient than DCT due to the following result:-
_ No need to divide the input coding into non-overlapping 2-D blocks, it has higher
compression ratios avoid blocking artifacts.
_ Allows good localization both in time and spatial frequency domain.
_ Transformation of the whole image_ introduces inherent scaling
_ Better identification of which data is relevant to human perception_ higher
compression rati

Flow Chart:
Start

Load the image in workspace

Read the image

Specify the original size of each row and column

Number of low-order samples to extract for the 3


cases (50%, 75%, 87.5% compression):

Store the results in matrices

Apply DCT to individual rows and columns

Apply IDCT to invidual rows and columns

Display the compressed images with corresponding


compression factors

End

You might also like