0% found this document useful (0 votes)
28 views

Lec13 Image-Compression Lec

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Lec13 Image-Compression Lec

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 104

Image Compression

Dr. Mohammad Motiur Rahman


Professor, Dept. of CSE, MBSTU
Image Compression
• The goal of image compression is to reduce the
amount of data required to represent a digital
image.
Compression Ratio

compression

Compression ratio:
Relevant Data Redundancy

Example:
The compression ratio is denoted by:

5
The reduction in file size is necessary to meet
the bandwidth requirements for many
transmission systems, and for the storage
requirements in computer databases

Also, the amount of data required for digital


images is enormous
6
Example 10.1.5 applies maximum data rate to Example 10.1.4

7
Why Can We Compress?

• Spatial redundancy
• Neighboring pixels are not independent but correlated

 Temporal redundancy
Fundamentals

• Basic data redundancies:


1. Coding redundancy
2. Inter-pixel redundancy
3. Psycho-visual redundancy
Coding Redundancy

Let us assume, that a discrete random variable rk in the interval [0,1]


represent the gray level of an image:
nk
pr (rk )  k 0,1, 2,  , L  1
n
If the number of bits used to represent each value of rk is l(rk), then the
average number of bits required
L 1
to represent each pixel:
Lavg  l (rk ) pr (rk )
k 0

The total number bits required to code an MxN image:


M .N .Lavg
Coding Redundancy

7
Lavg  l2 (rk ) pr (rk ) n1
k 0
CR 
2(0.19)  2(0.25)  2(0.21)  3(0.16)  4(0.08)
Compression ratio:
n2
 5(0.06)  6(0.03)  6(0.02) 1
Rd 1
Relative data redundancy:
2.7 bits CR
3 1
CR  1.11 Rd 1  0.099
2 .7 1.11
Coding Redundancy
Spatial Redundancy

Geometric Redundancy

Inter-pixel Redundancy Inter-frame Redundancy

Normalized Autocorrelation

A(n)
(n) 
A(0)
1 N  1 n
A(n)   f ( x, y) f ( x, y  n)
N  n y 0

H.R. Pourreza
Inter-pixel Redundancy

Original

Binary

C R 2.63
1
Rd 1  0.62
2.63

Run-length

H.R. Pourreza
Psycho-visual Redundancy

Elimination of psych-visual redundant data results in a loss quantitative information

Improved Gray-Scale

H.R. Pourreza
Psycho-visual Redundancy

IGS Quantization
Fidelity Criteria

The general classes of criteria :

1. Objective fidelity criteria

2. Subjective fidelity criteria


Fidelity Criteria

Objective fidelity:

Level of information loss can be expressed as a function of the original and the

compressed and subsequently decompressed image.

1/ 2
 1 M 1N1
ˆ 
Root-mean-square error
erms    2
[ f ( x, y )  f ( x, y )] 
 MN x 0 y 0 
M 1N1

 fˆ ( x, y ) 2
x 0 y 0
Mean-square signal-to-noise
SNRms  M  1 N  1
ratio
  [ fˆ ( x, y) 
x 0 y 0
f ( x, y )]2
Fidelity Criteria

Subjective fidelity (Viewed by Human):

• By absolute rating
• By means of side-by-side comparison of and
f ( x, y ) fˆ ( x, y )
Fidelity Criteria

erms 6.93 erms 6.78


SNRrm 10.25 SNRrm 10.39
Measuring Information
• We assume that information generation is a
probabilistic process.

• Idea: associate information with probability!

A random event E with probability P(E) contains:

Note: I(E)=0 when P(E)=1


How much information
does a pixel value contain?

• Suppose that gray level values are generated by a


random process, then rk contains:

units of information!

(assume statistically independent random events)


How much information does an image contain?

• Average information content of an image:


L 1
E  I (rk ) P(rk )
k 0

using

units/pixel
Entropy:
(e.g., bits/pixel)
Redundancy

• Redundancy:
(data vs info)

where:

Note: if Lavg= H, then R=0 (no redundancy)


Entropy Estimation
• It is not easy to estimate H reliably!

image
Entropy Estimation (cont’d)
• First order estimate of H:

Lavg = 8 bits/pixel R= Lavg- H

The first-order estimate provides only a lower-


bound on the compression that can be achieved.
Estimating Entropy (cont’d)
• Second order estimate of H:
• Use relative frequencies of pixel blocks :

image
Differences in Entropy Estimates

• Differences between higher-order estimates of


entropy and the first-order estimate indicate the
presence of interpixel redundancy!

• Need to apply some transformation to deal with


interpixel redundancy!
Differences in Entropy
Estimates (cont’d)
• Example: consider pixel differences

16
Differences in Entropy
Estimates (cont’d)
• What is the entropy of the pixel differences image?

(better than the entropy of the original image H=1.81)

• An even better transformation should be possible


since the second order entropy estimate is lower:
Image Compression Model

We will focus on the Source Encoder/Decoder only.


Classification
 Lossless compression
 lossless compression for legal and medical
documents, computer programs
 exploit only code and inter-pixel redundancy
 Lossy compression
 digital image and video where some errors or loss
can be tolerated
 exploit both code and inter-pixel redundancy and
sycho-visual perception properties
Data ≠ Information
• Data and information are not synonymous terms!

• Data is the means by which information is conveyed.

• Data compression aims to reduce the amount of data while


preserving as much information as possible.
Image Compression Model

We will focus on the Source Encoder/Decoder only.


Image Compression Model (cont’d)

• Mapper: transforms data to account for interpixel redundancies.


Image Compression Model (cont’d)

• Quantizer: quantizes the data to account for psychovisual


redundancies.
Image Compression Model (cont’d)

• Symbol encoder: encodes the data to account for coding


redundancies.
Image Compression Models (cont’d)

• The decoder applies the inverse steps.

• Note that quantization is irreversible in general.


Fidelity Criteria

• Criteria
• Subjective: based on human observers
• Objective: mathematically defined criteria
Subjective Fidelity Criteria
Lossless Compression
Taxonomy of Lossless Methods
Huffman Coding
(addresses coding redundancy)

• A variable-length coding technique.


• Source symbols are encoded one at a time!
• There is a one-to-one correspondence between source symbols and code
words.
• Optimal code - minimizes code word length per source symbol.
Huffman Coding (cont’d)
• Forward Pass
1. Sort probabilities per symbol
2. Combine the lowest two probabilities
3. Repeat Step2 until only two probabilities
remain.
Huffman Coding (cont’d)

• Backward Pass
Assign code symbols going backwards
Huffman Coding (cont’d)
• Lavg assuming Huffman coding:

• Lavg assuming binary coding:


Huffman Coding/Decoding
• Coding/Decoding can be implemented using a look-up table.
• Decoding can be done unambiguously.
Arithmetic (or Range) Coding
(addresses coding redundancy)
• Huffman coding encodes source symbols one at a time.
• Arithmetic coding encodes sequences of source symbols.
• Slower than Huffman coding but can achieve better compression.
• There is no one-to-one correspondence between source symbols and code
words.
Arithmetic Coding (cont’d)
• Represent a sequence of source symbols by a sub-interval in [0,1)
which can be encoded using an arithmetic code.

sub-interval arithmetic code


α1 α2 α3 α3 α4 [0.06752, 0.0688) 0.068
• Start with the interval [0, 1)
• As more symbols are encoded, a sub-interval is chosen to represent the
message which keeps shrinking as the message increases.
Arithmetic Coding (cont’d)

Suppose there are four symbols α1 α2 α3 α4

1) Start with interval [0, 1)

0 1
2) Subdivide [0, 1) based on the probabilities of α i

3) Update interval by processing message


Example

Encode
α1 α2 α3 α3 α4

[0.06752, 0.0688)
0.8

code: 0.068
0.4
(must be inside sub-interval)
0.2
Example (cont’d)
• The message α1 α2 α3 α3 αis4 encoded using 3 decimal digits or 3/5 =
0.6 decimal digits per source symbol.

• The entropy of this message is:

-(3 x 0.2log10(0.2)+0.4log10(0.4))=0.5786 digits/symbol

Note: finite precision arithmetic might cause problems due to


truncations!
Arithmetic Decoding
1.0 0.8 0.72 0.592 0.5728

α4
0.8 0.72 0.688 0.5856 0.57152

Decode 0.572
α3 (sequence length=5)

0.4 0.56 0.624 0.5728 0.56896

α2
0.2 0.48 0.592 0.5664 0.56768

α1 α3 α3 α1 α2 α4
0.0 0.4
0.56 0.56 0.5664
LZW Coding
(addresses interpixel redundancy)
• Requires no prior knowledge of symbol probabilities.

• Assigns fixed length code words to variable length


symbol sequences.
• There is no one-to-one correspondence between source
symbols and code words.

• Included in GIF, TIFF and PDF file formats


LZW Coding
• A codebook (or dictionary) needs to be
constructed.

• Initially, the first 256 entries of the dictionary are assigned


to the gray levels 0,1,2,..,255 (i.e., assuming 8 bits/pixel)
Initial Dictionary
Dictionary Location Entry

0 0
1 1
. .
255 255
256 -

511 -
LZW Coding (cont’d)
Example:
As the encoder examines image
39 39 126 126
pixels, gray level sequences
39 39 126 126
(i.e., blocks) that are not in the
39 39 126 126
dictionary are assigned to a new
39 39 126 126
entry.
Dictionary Location Entry

0 0
1 1
- Is 39 in the dictionary……..Yes
. . - What about 39-39………….No
255 255
256 - 39-39
* Add 39-39 at location 256
511 -
Example
39 39 126 126 Concatenated Sequence: CS = CR + P
39 39 126 126
(CR) (P)
39 39 126 126
39 39 126 126

CR = empty
repeat
P=next pixel
CS=CR + P
If CS is found:
(1) No Output
(2) CR=CS
else:
(1) Output D(CR)
(2) Add CS to D
(3) CR=P
Decoding LZW
• Use the dictionary for decoding the “encoded output”
sequence.
• The dictionary need not be sent with the encoded
output.
• Can be built on the “fly” by the decoder as it reads the
received code words.
Run-length coding (RLC)
(addresses interpixel redundancy)
• Reduce the size of a repeating string of symbols (i.e., runs):

1 1 1 1 1 0 0 0 0 0 0 1  (1,5) (0, 6) (1, 1)


a a a b b b b b b c c  (a,3) (b, 6) (c, 2)

• Encodes a run of symbols into two bytes: (symbol, count)


• Can compress any type of data but cannot achieve high
compression ratios compared to other compression
methods.
Combining Huffman Coding
with Run-length Coding
• Assuming that a message has been encoded using Huffman coding,
additional compression can be achieved using run-length coding.

e.g., (0,1)(1,1)(0,1)(1,0)(0,2)(1,4)(0,2)
Bit-plane coding
(addresses interpixel redundancy)

• Process each bit plane individually.

(1) Decompose an image into a series of binary images.


(2) Compress each binary image (e.g., using run-length coding)
Bitplane-RLC
A technique which involves extension of basic
RLC method to gray level images, by applying
basic RLC to each bit-plane independently

• For each binary digit in the gray level value, an


image plane is created, and this image plane (a
string of 0's and 1's) is then encoded using RLC

62
63
• Typical compression ratios of 0.5 to 1.2 are
achieved with complex 8-bit monochrome images

• Thus without further processing, this is not a


good compression technique for complex images

• Bitplane-RLC is most useful for simple images,


such as graphics files, where much higher
compression ratios are achieved

64
• The compression results using this method can
be improved by preprocessing to reduce the
number of gray levels, but then the compression
is not lossless

• With lossless bitplane RLC we can improve the


compression results by taking our original pixel
data (in natural code) and mapping it to a Gray
code (named after Frank Gray), where adjacent
numbers differ in only one bit

65
• As the adjacent pixel values are highly
correlated, adjacent pixel values tend to be
relatively close in gray level value, and this can
be problematic for RLC

66
Lossy Methods - Taxonomy
Lossy Compression
• Transform the image into some other domain to
reduce interpixel redundancy.
Example: Fourier Transform

Note that the


magnitude of the FT
decreases, as u, v
increase!

K << N
K-1 K-1
Transform Selection

• T(u,v) can be computed using various transformations, for example:


• DFT
• DCT (Discrete Cosine Transform)
• KLT (Karhunen-Loeve Transformation) or Principal Component Analysis (PCA)

• JPEG uses DCT for handling interpixel redundancy.


DCT (Discrete Cosine Transform)

Forward:

Inverse:

if u=0 if v=0
if u>0 if v>0
DCT (cont’d)
• Basis functions for a 4x4 image (i.e., cosines of different frequencies).
DCT (cont’d)
Using DFT WHT DCT
8 x 8 sub-images
yields 64 coefficients
per sub-image.

Reconstructed images
by truncating
50% of the
coefficients

DCT is a more compact


transformation!

RMS error: 2.32 1.78 1.13


DCT (cont’d)

• Sub-image size selection:

Reconstructions

original 2 x 2 sub-images 4 x 4 sub-images 8 x 8 sub-images


DCT (cont’d)
• DCT minimizes "blocking artifacts" (i.e., boundaries
between subimages do not become very visible).

DFT
has n-point periodicity

DCT
has 2n-point periodicity
JPEG Compression

Entropy
encoder

Accepted as
an
international
image
compression
standard in
1992.
Entropy
decoder
JPEG - Steps
1. Divide image into 8x8 subimages.

For each subimage do:


2. Shift the gray-levels in the range [-128, 127]

3. Apply DCT  64 coefficients


1 DC coefficient: F(0,0)
63 AC coefficients: F(u,v)
Example

[-128, 127] (DCT - non-centered


spectrum)
JPEG Steps

4. Quantize the coefficients (i.e., reduce the


amplitude of coefficients that do not contribute a
lot).

Q(u,v): quantization table


Example
• Quantization Table Q[i][j]
Example (cont’d)

Quantization
JPEG Steps (cont’d)
5. Order the coefficients using zig-zag ordering
- Creates long runs of zeros (i.e., ideal for run-length encoding)
JPEG Steps (cont’d)

6. Encode coefficients:

6.1 Form “intermediate” symbol sequence.

6.2 Encode “intermediate” symbol sequence into


a binary sequence.
Intermediate Symbol Sequence
– DC coeff

symbol_1 (SIZE) symbol_2 (AMPLITUDE)


DC (6) (61)

SIZE: # bits need to encode


the coefficient
DC Coefficient Encoding

symbol_1 symbol_2
(SIZE) (AMPLITUDE)

predictive
coding:
Intermediate Symbol
Sequence – AC coeff

symbol_1 (RUN-LENGTH, SIZE) symbol_2 (AMPLITUDE) end of block


AC (0, 2) (-3)
RUN-LENGTH: run of zeros preceding coefficient
SIZE: # bits for encoding the amplitude of coefficient
Note: If RUN-LENGTH > 15, use symbol (15,0) ,
Example: AC Coefficients Encoding
Symbol_1 Symbol_2
(Variable Length Code (VLC)) (Variable Length Integer (VLI))

# bits

(1,4) (12)  (111110110 1100)


VLC VLI
Final Symbol Sequence
What is the effect of the “Quality”
parameter?

(58k bytes) (21k bytes) (8k bytes)

lower compression higher compression


What is the effect of the “Quality”
parameter? (cont’d)
Effect of Quantization:
homogeneous 8 x 8 block
Effect of Quantization:
homogeneous 8 x 8 block (cont’d)
Quantized De-quantized
Effect of Quantization:
homogeneous 8 x 8 block (cont’d)
Reconstructed
Error is low!

Original
Effect of Quantization:
non-homogeneous 8 x 8 block
Effect of Quantization:
non-homogeneous 8 x 8 block
(cont’d)
Quantized De-quantized
Effect of Quantization:
non-homogeneous 8 x 8 block
(cont’d)
Reconstructed

Error is high!

Original:
Case Study: Fingerprint
Compression
• FBI is digitizing fingerprints at 500 dots per inch with 8 bits of
grayscale resolution.
• A single fingerprint card turns into about 10 MB of data!

A sample fingerprint image


768 x 768 pixels =589,824 bytes
WSQ Fingerprint Compression
• An image coding standard for digitized fingerprints employing the
Discrete Wavelet Transform (Wavelet/Scalar Quantization or WSQ).

• Developed and maintained by:


• FBI
• Los Alamos National Lab (LANL)
• National Institute for Standards and Technology (NIST)
Need to Preserve Fingerprint Details

The "white" spots in the middle of


the black ridges are sweat pores and
they are admissible points of
identification in court.

These details are just a couple


pixels wide!
What compression scheme should be used?

• Lossless or lossy compression?

• In practice lossless compression methods haven’t done better than


2:1 on fingerprints!

• Does JPEG work well for fingerprint compression?


Results using JPEG compression
file size 45853 bytes
compression ratio: 12.9

Fine details have been lost.

Image has an artificial ‘‘blocky’’


pattern superimposed on it.

Artifacts will affect the


performance of fingerprint
recognition.
Results using WSQ compression
file size 45621 bytes
compression ratio: 12.9

Fine details are better


preserved.

No “blocky” artifacts.
WSQ Algorithm

You might also like