Download as pdf or txt
Download as pdf or txt
You are on page 1of 60

MOD 6

Image Compression
Arithmetic coding
Compression
KTUStudents.in
standards

Anjana Devi
AP in ECE
For more study materials: WWW.KTUSTUDENTS.IN
CE, Cherthala 1
 Arithmetic Coding

• Arithmetic coding transforms input data into a single


floating point number between 0 and 1

There is not a direct correspondence between the


KTUStudents.in

code and the individual pixel values

For more study materials: WWW.KTUSTUDENTS.IN 2


• As each input symbol (pixel value) is read the
precision required for the number becomes greater

• As the images are very large and the precision of


digital computers is finite, the entire image must be
divided into small subimages to be encoded

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN 3


• Arithmetic coding uses the probability distribution of
the data (histogram), so it can theoretically achieve
the maximum compression specified by the entropy

• It works by successively subdividing the interval


between 0 and 1, based on the placement of the

KTUStudents.in
current pixel value in the probability distribution

For more study materials: WWW.KTUSTUDENTS.IN 4


KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN 5


KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN 6


• In practice, this technique may be used as part of an
image compression scheme, but is impractical to
use alone

• It is one of the options available in the JPEG


standard

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN 7


 Lossy Encoding methods
 Transform based compression

• Transform based compression, is a type of lossy


compression done in the transform domain
KTUStudents.in
• The image is divided into non overlapping blocks, or
subimages, and the transform is calculated for each
block
• ie, each block is expressed as a sum of discrete basis
functions

For more study materials: WWW.KTUSTUDENTS.IN 8


• The purpose of transform coding is to decompose
the correlated signal samples into a set of
uncorrelated transform coefficients
• The main reason for mapping the original data into
another mathematical space is to pack the
information (or energy) into as few coefficients as
possible
KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN 9


Transform based
compression

KTUStudents.in

Block Transform coding system


For more study materials: WWW.KTUSTUDENTS.IN
• Reasons for block processing
• To reduce memory required for computations
• Spatial localisation is required for efficient
decorrelation of the coeff values to reduce
redundancy
• If the transform is not spatially localised we have to

KTUStudents.in
do this separately prior to taking the forward
transform
• Eg: required for DCT, but not for wavelet transform
• Disadv of block processing
– Introduction of block artifacts
• discontinuities in the adjacent regions resulting
from rectangular windowing

For more study materials: WWW.KTUSTUDENTS.IN 11


• Forward Transform and transform coding
• The transform recognises the gray values of the image and
then changes the correlation properties of the image
• Any of the previously defined transforms can be used,
frequency (e.g. Fourier) or sequency (e.g. Walsh/Hadamard),
but it has been determined that the discrete cosine transform
(DCT) is optimal for most images

KTUStudents.in
The newer JPEG2000 algorithms uses the wavelet

transform, which has been found to provide even better


compression
• After taking FDCT, transform coding is performed by
eliminating few irrelevant coefficients
• The simplest form of transform coding is achieved by filtering
by eliminating some of the high frequency coefficients

For more study materials: WWW.KTUSTUDENTS.IN 12


• Properties of the transform for efficient
compression

• 1. Decorrelation-
– Transform should generate less correlated or
uncorrelated coefficients to achieve high

KTUStudents.in
compression ratio
• 2. Linearity
– Allows one to one mapping between pixel values
and transform coefficients
• 3. Orthogonality
– To eliminate redundancy in the transformed
image

For more study materials: WWW.KTUSTUDENTS.IN 13


• Quantization
• After the transform has been calculated, the transform
coefficients are quantized and coded

• Quantisation is the process of reducing the no. of


possible values of a quantity, thereby reducing the

KTUStudents.in
number of bits needed to represent it.
• This method is effective because the
frequency/sequency transform of images is very efficient
at putting most of the information into relatively few
coefficients, so many of the high frequency coefficients
can be quantized to 0 (eliminated completely)
• Irreversible process

For more study materials: WWW.KTUSTUDENTS.IN 14


• Need for quantization
• The simplest form of transform coding is achieved
by filtering by eliminating some of the high frequency
coefficients

• However, this will not provide much compression,

KTUStudents.in
since the transform data is typically floating point
and thus 4 or 8 bytes per pixel (compared to the
original pixel data at 1 byte per pixel), so
quantization and coding is applied to the reduced
data after the transformation phase.

For more study materials: WWW.KTUSTUDENTS.IN 15


• Quantization includes a process called bit allocation,
which determines the number of bits to be used to
code each coefficient.
• Uniform and non uniform quantization
– In Uniform type, the quantization levels are
uniformly spaced, whereas in non-uniform type the
spacing between the levels will be unequal and


KTUStudents.in
mostly the relation is logarithmic.
Typically non uniform quantisation is used for image
compression
• More bits are used for lower frequency components
where the energy is concentrated for most images,
resulting in a variable bit rate or nonuniform
quantization and better resolution

For more study materials: WWW.KTUSTUDENTS.IN 16


KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN 17


KTUStudents.in

Mid – tread type:Quantization levels – odd number.

Mid – Rise type: Quantization levels – even number.

For more study materials: WWW.KTUSTUDENTS.IN 18


KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN 19


• Entropy Encoder

• The purpose of entropy encoder is to reduce the


number of bits required to represent each
symbol/value at the quantizer output..
• The coefficients can be coded using, for example, a
Huffman or arithmetic coding method

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN 20


• Transform coding
• Two particular types of transform coding have
been widely explored:
1. Zonal coding
2. Threshold coding


KTUStudents.in
These two vary in the method they use for
selecting the transform coefficients to be retained
before quantization and encoding stages.
• selects the coefficients based on
– Max Variance
– A threshold

For more study materials: WWW.KTUSTUDENTS.IN 21


1. Zonal coding

• It involves selecting specific coefficients based on


maximal variance
• Coeffs of max variance carry the most picture
information
A zonal mask is determined for the entire image by
KTUStudents.in

finding the variance for each frequency component
• This variance is calculated by using each subimage
within the image as a separate sample and then
finding the variance within this group of subimages
• Locations of the coeff with the K largest variances
are indicated in the mask
• All coeff outside the zone are kept zero

For more study materials: WWW.KTUSTUDENTS.IN 22


• The zonal mask is a bitmap of 1's and 0', where the
1's correspond to the coefficients to retain, and the
0's to the ones to eliminate

• As the zonal mask applies to the entire image, only


one mask is required

KTUStudents.in
Typical masks may be square, triangular or circular
and the cut off frequency is determined by the
compression ratio

For more study materials: WWW.KTUSTUDENTS.IN 23


KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN 24


• In practice, the zonal mask is often predetermined
because the low frequency terms tend to contain the
most information, and hence exhibit the most
variance

• In this case we select a fixed mask of a given shape

KTUStudents.in
and desired compression ratio, which streamlines
the compression process

For more study materials: WWW.KTUSTUDENTS.IN 25


2. Threshold coding

• It selects the transform coefficients based on


specific value
• Each transform coeff is compared with a
threshold , if it is smaller the coeff is set to zero


KTUStudents.in
Otherwise the coeff will be retained
A different threshold mask is required for each
block
• Therefore adaptive method
• Increases file size as well as algorithmic
complexity

For more study materials: WWW.KTUSTUDENTS.IN 26


Figure 10.3-18
Zonal Compression with DCT and Walsh Transforms

A block size of 64x64 was used, a circular zonal mask, and DC coefficients were not qua

KTUStudents.in
a) Original image, a view of c) Error image comparing the
St. Louis, Missouri, from original and (b), histogram
the Gateway Arch stretched to show detail

b) Results from using the DCT


with a compression ratio = 4.27

For more study materials: WWW.KTUSTUDENTS.IN 27


Figure 10.3-18
Zonal Compression with DCT and Walsh Transforms
(contd)

KTUStudents.in
d) Results from using the DCT with e) Error image comparing the original and
a compression ratio = 14.94 (d), histogram stretched to show detail,

For more study materials: WWW.KTUSTUDENTS.IN 28


• JPEG
• One of the most commonly used image
compression standards is primarily a form of
transform coding
• The Joint Photographic Expert Group (JPEG) under
the auspices of the International Standards
KTUStudents.in
Organization (ISO) devised a family of image
compression methods for still images
• The original JPEG standard uses the DCT and 8x8
pixel blocks as the basis for compression

For more study materials: WWW.KTUSTUDENTS.IN 29


Why JPEG
The compression ratio of lossless methods (e.g.,
Huffman, Arithmetic, LZW) is not high enough for
image and video compression.
JPEG uses transform coding, it is largely based on
the following observations:
Observation 1: A large majority of useful image contents

KTUStudents.in
change relatively slowly across images, i.e., it is unusual for
intensity values to alter up and down several times in a
small area, for example, within an 8 x 8 image block.
A translation of this fact into the spatial frequency domain,
implies, generally, lower spatial frequency components
contain more information than the high frequency
components which often correspond to less useful details
and noises.
Observation 2: Experiments suggest that humans are more
immune to loss of higher spatial frequency components
than loss of lower frequency components.

For more study materials: WWW.KTUSTUDENTS.IN 30


JPEG Coding
Cr
Cb
f(i, j) F(u, v) Fq(u, v) Steps Involved:
Y DCT Quantization Discrete Cosine Transform
of each 8x8 pixel array
8x8 8x8
f(x,y) T F(u,v)
Quantization using a table
Quant… or using a constant
Tables
Zig-Zag scan to exploit

KTUStudents.in
Coding redundancy
Tables Zig Zag
Scan Differential Pulse Code
Modulation(DPCM) on
Header
the DC component and
Tables
Run length Coding of
DPCM the AC components
Data Entropy Entropy coding (Huffman)
Coding of the final output
RLC

For more study materials: WWW.KTUSTUDENTS.IN 31


KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN 32


DCT : Discrete Cosine Transform
DCT converts the information contained in a block(8x8) of
pixels from spatial domain to the frequency domain.
 A simple analogy: Consider a unsorted list of 12 numbers
between 0 and 3 -> (2, 3, 1, 2, 2, 0, 1, 1, 0, 1, 0, 0).
Consider a transformation of the list involving two steps
(1.) sort the list (2.) Count the frequency of occurrence of

KTUStudents.in
each of the numbers ->(4,4,3,1 ). : Through this
transformation we lost the spatial information but captured
the frequency information.
 There are other transformations which retain the spatial
information. E.g., Fourier transform, DCT etc. Therefore
allowing us to move back and forth between spatial and
frequency domains.

For more study materials: WWW.KTUSTUDENTS.IN 33


Why DCT
1. DCT retains spatial information
2. possesses good variance distribution which
leads to efficient energy compaction in the
KTUStudents.in
transform domain
3. DCT meets all the properties required for a
transform to be used for image compression
a) decorrelation
b) linearity
c) orthogonality

For more study materials: WWW.KTUSTUDENTS.IN 34


Example and Comparison

DFT
DCTDCT FFT

100 -52 0 -5 0 -2 0 0.4 36 10 10 6 6 4 4 4

KTUStudents.in
100 -52 0 -5 0 -2 0 0.4 36 10 10 6 6 4 4 4
Inverse DCT Inverse FFT
8 15 24 32 40 48 57 63 24 12 20 32 40 51 59 48

Example Description:
 f(n) is given from n = 0 to 7; (N=8)
 Using DCT(FFT) we compute F(ω) for ω = 0 to 7
 We truncate and use Inverse Transform to compute f’(n)
For more study materials: WWW.KTUSTUDENTS.IN 35
2-D DCT
 Images are two-dimensional; How do you perform 2-D
DCT?
 Two series of 1-D transforms result in a 2-D transform as
demonstrated in the figure below
f (i,j )

KTUStudents.in
1-D 1-D
Row- Column-
wise wise

8x8 8x8 8x8

F (u,v)

 F(0,0) is called the DC component and the rest of F(i,j) are


called AC components

For more study materials: WWW.KTUSTUDENTS.IN 36


Quantization
 Why? -- To reduce number of bits per sample
F’(u,v) = round(F(u,v)/q(u,v))
 Example: 101101 = 45 (6 bits).
Truncate to 4 bits: 1011 = 11. (Compare 11 x 4 =44
against 45)
Truncate to 3 bits: 101 = 5. (Compare 8 x 5 =40 against
45)
KTUStudents.in
Note, that the more bits we truncate the more precision we lose
 Quantization error is the main source of the Lossy
Compression.

For more study materials: WWW.KTUSTUDENTS.IN 37


Quantization
 Uniform Quantization:
 q(u,v) is a constant.
 Non-uniform Quantization -- Quantization Tables
 Eye is most sensitive to low frequencies (upper left corner in
frequency matrix), less sensitive to high frequencies (lower
right corner)


KTUStudents.in
Custom quantization tables can be put in image/scan
header.
JPEG Standard defines two default quantization tables, one
each for luminance and chrominance.

For more study materials: WWW.KTUSTUDENTS.IN 38


Quantization Matrix
 Defines the quantization step size
 Small for low freq components and large for high
freq components
 The values of step size are governed by the
psycho visual properties of the human visual
system

KTUStudents.in
 DCT coefficient matrix after transform coding is divided by the
quantization matrix and then rounded to the nearest integer
 High freq components become zero after this process
 Eliminates psycho visual redundancy and irrelevancy
 Makes it easier for the next stage of entropy coding

For more study materials: WWW.KTUSTUDENTS.IN 39


Zig-Zag Scan
 The spectrum of DCT falls off withincreasing freq
 To make entropy encoding (RLC) more efficient, the
highest freq should be visited last (ie, small values)
 Groups low frequency coefficients in top of 2D freq space
and high frequency coefficients at the bottom

KTUStudents.in
 Maps 8 x 8 matrix to a 1 x 64 vector

8x8

...
For more study materials: WWW.KTUSTUDENTS.IN
1x64
40
DPCM on DC Components
 The DC component value in each 8x8 block is large and
varies across blocks, but is often close to that in the
previous block.
 Differential Pulse Code Modulation (DPCM): Encode the
difference between the current and previous 8x8 block.

KTUStudents.in
Remember, smaller number -> fewer bits
45 45
1x64 1x64

54 9
1x64 1x64

48 -6
1x64 1x64
. .
. .
. .
32 12
1x64 1x64
36 4
41
1x64 1x64
For more study materials: WWW.KTUSTUDENTS.IN
Entropy Coding: AC Components
 AC components are coded using Run length and Huffman coding

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN 42


JPEG Modes
Sequential Mode:
 Each image is encoded in a single left-to-right,
top-to-bottom scan.
 The technique we have been discussing so far is an

KTUStudents.in
example of such a mode, also referred to as the
Baseline Sequential Mode.
 Default JPEG mode
 It supports only 8-bit images

For more study materials: WWW.KTUSTUDENTS.IN 43


JPEG Modes
Lossless Mode:
 Truly lossless
 It is a predictive coding mechanism as opposed to the
baseline mechanism which is based on DCT and

KTUStudents.in
quantization(the source of the loss).
 Used in medical image compression
 Here is the simple block diagram of the technique:
Predictive
Difference

Huffman
Lossless
EnCoder
Coding

For more study materials: WWW.KTUSTUDENTS.IN 44


JPEG Modes
Progressive Mode: It allows a coarse version of
an image to be transmitted at a low rate,
which is then progressively improved over
subsequent transmissions.
 Spectral Selection : Send DC component and first few

KTUStudents.in
AC coefficients first, then gradually some more ACs.

Spectral
Selection:
First Scan:
Second
Scan:
Third Scan:
.
.

Nth Scan:
Image Pixels

For more study materials: WWW.KTUSTUDENTS.IN 45


JPEG Modes
Progressive Mode: widely supported in web
browsers
multiple scans of images are produced
UsefUL WHEN THE SPEED OF communication is low
Adv of progressive mode

KTUStudents.in
User has a choice whether to continue receiving the image
data after the first scan
3 algorithms exist in progressive mode.
a) Progressive spectral selection
b) Progressive successive approximation
c) combined progressive algorithm

a) Progressive spectral selection


DC coeff are transmitted first, followed by low freq and
For more study materials: WWW.KTUSTUDENTS.IN 46
high freq coeff.
Progressive Mode
 Successive Approximation : All the DCT components are
sent few bits at a time: For example, send n1 (say,4)
bits (starting with MSB) of all pixels in the first scan, the
next n2(say 1) bits of all pixels in the second and so on.

MSB
KTUStudents.in
7 6 5 4 3 2 1 0 LSB
Pixels ordered (zig-zag-wise)

One Pixel First Scan: ...

Second ...
Scan:
Third Scan: ...
. .
. .
5th Scan: ...

For more study materials: WWW.KTUSTUDENTS.IN 47


Hierarchical Mode
 Encodes the image in a hierarchy of several different
resolutions
 A pyramid of images is created by arranging the images
according to the resolution
 Each lower resolution image is used as a prediction for

KTUStudents.in
the next higher resolution pyramid level
 Used primarily to support multiple resolutions of the
same image which can be chosen from depending on
the target’s capabilities.
 In applications in which a very high resolution image
must be accessed by a lower resolution display

For more study materials: WWW.KTUSTUDENTS.IN 48


• SUMMARY OF JPEG COMPRESSION

• Before computing the DCT, the pixel values are level


shifted so that they are centered at zero

• EXAMPLE 10.3.7:
KTUStudents.in
A typical 8-bit image has a range of gray levels of 0
to 255. Level shifting this range to be centered at
zero involves subtracting 128 from each pixel value,
so the resulting range is from -128 to 127

For more study materials: WWW.KTUSTUDENTS.IN 49


• After level shifting, the DCT is computed

• Next, the DCT coefficients are quantized by dividing


by the values in a quantization table and then
truncated

KTUStudents.in
• For color signals JPEG transforms the RGB
components into the YCrCb color space, and
subsamples the two color difference signals (Cr and
Cb), since we perceive more detail in the luminance
(brightness) than in the color information

For more study materials: WWW.KTUSTUDENTS.IN 50


• Once the coefficients are quantized, they are coded
using a Huffman code

• The zero-frequency coefficient (DC term) is


differentially encoded relative to the previous block

KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN 51


KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN 52


Figure 10.3-21:The Original DCT-based JPEG
Algorithm Applied to a Color Image

KTUStudents.in

a) The original image b) Compression ratio = 34.34

For more study materials: WWW.KTUSTUDENTS.IN 53


Figure 10.3-21:The Original DCT-based JPEG
Algorithm Applied to a Color Image (contd)

KTUStudents.in

e) Compression ratio = 131.03 f) Compression ratio = 201.39

For more study materials: WWW.KTUSTUDENTS.IN 54


 Hybrid and Wavelet Methods

• Hybrid methods use both the spatial and spectral


domains

Algorithms exist that combine differential coding and


KTUStudents.in

spectral transforms for analog video compression

For more study materials: WWW.KTUSTUDENTS.IN 55


• The JPEG2000 standard is also based on the
wavelet transform

• It provides high quality images at very high


compression ratios


KTUStudents.in
The committee that developed the standard had
certain goals for JPEG2000

For more study materials: WWW.KTUSTUDENTS.IN 56


• The goals are as follows:

1. To provide better compression than the DCT-


based JPEG algorithm

1. To allow for progressive transmission of high

KTUStudents.in
quality images

1. To be able to compress binary and continuous


tone images by allowing 1 to 16 bits for image
components

For more study materials: WWW.KTUSTUDENTS.IN 57


4. To allow random access to subimages

5. To be robust to transmission errors

5. To allow for sequentially image encoding


KTUStudents.in
The JPEG2000 compression method begins by
level shifting the data to center it at zero, followed
by an optional transform to decorrelate the data,
such as a color transform for color images

For more study materials: WWW.KTUSTUDENTS.IN 58


• The one-dimensional wavelet transform is applied to
the rows and columns, and the coefficients are
quantized based on the image size and number of
wavelet bands utilized

• These quantized coefficients are then arithmetically

KTUStudents.in
coded on a bitplane basis

For more study materials: WWW.KTUSTUDENTS.IN 59


KTUStudents.in

For more study materials: WWW.KTUSTUDENTS.IN 60

You might also like