## JPEG Image Compression

Rahul Garg, Varun Gulshan December 6, 2005

JPEG Image Compression

## Basic Data Redundancies

• Interpixel Redundancy

• Psychovisual Redundancy

• Coding Redundancy

## A Bit of Information Theory

Entropy of a source : Average amount of information obtained by observing a single source output.

H(z) = −

N

X

i=1

P (a_{i})logP (a_{i})

where (a_{1}, a_{2}, ..., a_{N}) forms the set of possible
outputs.Shannon’s First Theorem states that

min(L_{avg}) = H(z)

where L_{avg} is average code word length per source symbol.

JPEG Image Compression 2

## Encoding Process

## Handling Redundancies

• Interpixel Redundancy: Captured by the DCT coefficients(more zeros in coeffs).

• Psychovisual Redundancy: Captured by the high frequency DCT coefficients.

• Coding Redundancy: Captured by variable length codes.

JPEG Image Compression 4

## The DCT transform

• Break up image into 8x8 image blocks.

• Change the basis for representing the block image.

The (u, v)^{th} DCT coefficient is given by the dot product

dct (u, v) =

N −1

X

x=0

N −1

X

y=0

image (x, y) ∗ h (x, y, u, v)

where

h (x, y, u, v) = α(u)α(v)cos

h(2x+1)uπ 2N

i

cos

h(2y+1)vπ 2N

i

JPEG Image Compression 6

### Information packing in DCT coeffs

## DCT vs FT

Comparison of packing for a one dimensional test signal:[8, 16, 32, 40, 48, 56, 64]

JPEG Image Compression 8

Effect of truncation

Result on images

JPEG Image Compression 10

## Quantization

• Equivalent to truncating coefficients corresponding to high frequency.

• Lossy step in JPEG compression.

• Quantization values specified in a 8x8 Q-table.

• Table based on heuristically determined perceptual importance of each coefficient.

JPEG Image Compression 12

## Coding of the DCT coefficients

Done in two parts

• The DC coefficient (u, v) = (0, 0) is coded using difference encoding.

• The AC coefficients(the rest of the coefficients) are run length encoded and then huffman coded.

## Coding the DC coefficients

Step 1: Take difference with the DC coefficient of the previous block.

JPEG Image Compression 14

Step 2: Differences are encoded using variable length codes.These variable length codes are standardized for jpeg.

DC coeffs -869 → -861 → -876 → -933 → -867 → -845 → -863 ...

Differences 8 -15 -57 66 22 -18 ...

Codes for differences are looked up from a table.

## Coding the AC coefficients

Step 1: Convert the AC coefficients into a sequence by traversing the coefficients in a zig-zag way.

Zig-zag parse clusters the zeros together.

JPEG Image Compression 16

Example zig zag parse

⇓

-26 -3 1 -3 -2 -6 2 -4 1 -4 1 1

5 0 2 0 0 -1 2 0 0 0 0 0 -1 -1 EOB

Step 2: Non zero AC coefficients are divided into categories.

Figure 1: AC categories The sequence is then run length coded.

JPEG Image Compression 18

Original AC coeff -26 -3 1 -3 -2 -6 2 -4 1 -4 1 1 5 0

2 0 0 -1 2 0 0 0 0 0 -1 -1 EOB

⇓

Category codes 5 2 1 2 2 3 2 3 1 3 1 1 3 -

2 - - 1 2 - - - - - 1 1 EOB

⇓

Run length codes 0/5 0/2 0/1 0/2 0/2 0/3 0/2 0/3 0/1 0/3 0/1 0/1 0/3

1/2 2/1 0/2 5/1 0/1 EOB

Run length codes form our symbol set for coding. They are coded using a standardized table. Hence, code for each non zero AC coefficient is composed of a basecode (corresponding to runlength/category) and a code corresponding to offset in

## Standard tables vs Optimized tables

JPEG Image Compression 20

## JPEG Variants

• Progressive JPEG : Image stored in series of scans with image becoming sharper with each scan.

• Lossless JPEG : Utilizes Predictive Differential Coding method.

• JPEG 2000 : Latest version of JPEG relying on wavelet transformation instead of DCT.

## References

• Digital Image Processing by R.C. Gonzalez and R.E. Woods

• http://www.jpeg.org

• http://cnx.rice.edu

• http://www.datacompression.info

• http://www.cs.sfu.ca

• http://www.wikipedia.org

JPEG Image Compression 22