Sie sind auf Seite 1von 74

Fundamentals of Image and Video Processing

Image Compression

Types of Data

Need for compression

Compression Scheme

Image Compression Model

Compression Measures

Types of Compression

Lossless Vs Lossy

Another Way of Classification

Types of Redundancy

Coding Redundancy

Interpixel Redundancy

Psychovisual Redundancy

Run Length Coding

Vertical Scanning

2D RLC

Make-up Code

2D RLC

Huffman Coding

Example

Canonical Huffman code

Truncated Huffman codes

Huffman Shift Code

Shannon- Fano Coding

Bitplane Coding

Bitplane coding

Arithmetic Coding

Dictionary Based Encoding

Decoding

Lossless Predictive Coding

Lossless Predictive coding

Dictionary Based
Compression
LZW Algorithm

The LZW Algorithm (Compression)

W = NIL;
while (there is input){
K = next symbol from input;
if (WK exists in the dictionary) {
W = WK;
} else {
output (index(W));
add WK to the dictionary;
W = K;
}
}

START

The LZW Algorithm (Compression) Flow Chart


W= NULL

YES
STOP

IS EOF
?

NO

K=NEXT INPUT

YES
W=WK

IS WK
FOUND?
NO
OUTPUT INDEX OF W
ADD WK TO DICTIONARY

W=K

Input string is

The LZW Algorithm (Compression) Example

The Initial
Dictionary
contains
symbols like
a, b, c, d with
their index
values as 1,
2, 3, 4
respectively.
Now the input
string is read
from left to
right.
Starting from
a.

a b d c a d a c

a
b
c
d

1
2
3
4

The LZW Algorithm (Compression) Example

W = Null
K=a
WK = a
In the
dictionary.

a b d c a d a c
K

a
b
c
d

1
2
3
4

The LZW Algorithm (Compression) Example

K = b.
WK = ab
is not in the
dictionary.
Add WK to
dictionary
Output code
for a.
Set W = b

a b d c a d a c
K

1
a
b
c
d

1 a
2 b
3
4

The LZW Algorithm (Compression) Example

K=d
WK = bd
Not in the
dictionary.
Add bd to
dictionary.
Output code
b
Set W = d

a b d c a d a c
K

1 2
a
b
c
d

1
2
3
4

a
b
d

5
6

The LZW Algorithm (Compression) Example

K=a
WK = da
not in the
dictionary.
Add it to
dictionary.
Output code
d
Set W = a

a b d a b d a c
K

1 2 4
a
b
c
d

1
2
3
4

a
b
d
a

5
6
7

The LZW Algorithm (Compression) Example

K=b
WK = ab
It is in the
dictionary.

a b d a b d a c
K

1 2 4
a
b
c
d

1
2
3
4

a
b
d
a

5
6
7

The LZW Algorithm (Compression) Example

K=d
WK = abd
Not in the
dictionary.
Add W to the
dictionary.
Output code
for W.
Set W = d

a b d a b d a c
K

1 2 4 5
a
b
c
d

1
2
3
4

a
b
d
a
ab
d

5
6
7
8

The LZW Algorithm (Compression) Example

K=a
WK = da
In the dictionary.

a b d a b d a c
K

1 2 4 5
a
b
c
d

1
2
3
4

a
b
d
a
ab
d

5
6
7
8

The LZW Algorithm (Compression) Example

K=c
WK = dac
Not in the dictionary.
Add WK to the
dictionary.
Output code for W.
Set W = c
No input left so
output code for W.

a b d a b d a c
K

1 2 4 5 7
a
b
c
d

1
2
3
4

a
b
d
a
ab
d

5 da 9
6 c
7
8

The LZW Algorithm (Compression) Example

The final output


string is
124573
Stop.

a b d a b d a c
K

1
a
b
c
d

1 ab 5
2 bd 6
3 da 7
4 abd 8

7 3
dac

LZW Decompression Algorithm


read a character k;
output k;
w = k;
while ( read a character k )
/* k could be a character or a code. */
{

entry = dictionary entry for k;


output entry;
add w + entry[0] to dictionary;
w = entry; }

START

LZW Decompression Algorithm Flow Chart


K=INPUT
Output K
W=K
YES
IS EOF
?

NO
K=NEXT INPUT
ENTRY=DICTIONARY INDEX (K)
Output ENTRY
ADD W+ENTRY[0] TO DICTIONARY

W=ENTRY

STOP

The LZW Algorithm (Decompression) Example

K=1
Out put K (i.e. a)
W=K

a
a
b
c
d

1
2
3
4

The LZW Algorithm (Decompression) Example

K=2
entry = b
Output entry
Add W + entry[0] to
dictionary
W = entry[0] (i.e. b)

a b
a
b
c
d

1
2
3
4

ab

The LZW Algorithm (Decompression) Example

K=4
entry = d
Output entry
Add W + entry[0] to
dictionary
W = entry[0] (i.e. d)

a b d
a
b
c
d

1 ab
2 bd
3
4

5
6

The LZW Algorithm (Decompression) Example

K=5
entry = ab
Output entry
Add W + entry[0] to
dictionary
W = entry[0] (i.e. a)

5
K

a b d a b
a
b
c
d

1 ab
2 bd
3 da
4

5
6
7

The LZW Algorithm (Decompression) Example

K=7
entry = da
Output entry
Add W + entry[0] to
dictionary
W = entry[0] (i.e. d)

a b d a b d a
a
b
c
d

1 ab 5
2 bd 6
3 da 7
4 abd 8

The LZW Algorithm (Decompression) Example

K=3
entry = c
Output entry
Add W + entry[0] to
dictionary
W = entry[0] (i.e. c)

3
K

a b d a b d a c
a
b
c
d

1 ab 5
2 bd 6
3 da 7
4 abd 8

dac

Advantages

As LZW is adaptive dictionary


coding no need to transfer the
dictionary explicitly.
It will be created at the decoder
side.
LZW can be made really fast, it
grabs a fixed number of bits from
input, so bit parsing is very easy,
and table look up is automatic.

Lossy Compression
Methods
In order to achieve high compression ratios with complex
images, lossy compression methods are required.
Lossy compression provides trade-offs between image
quality and file reduction size.
With some of the more advanced methods, images can be
compressed 10 to 20 times with virtually no visible
information loss, and 30 to 50 times with minimal
degradation.

Lossy Compression

- Example

Lossy Compression

- Methods

Spatial Domain Methods:


Gray-level runlength coding (GLRLC)
Differential Predictive
Coding (DPC)
Block Truncation Coding
(BTC)
Vector Quantization (VQ)
Transform Domain Methods:
Zonal Coding
Threshold Coding
Hybrid Methods:
Wavelet-based

Filtering
JPEG algorithm
Model-based

Why Lossy?
In most applications related to
consumer electronics, lossless
compression is not necessary
What we care is the subjective quality of
the decoded image, not those intensity
values

With the relaxation, it is possible to


achieve a higher compression ratio
(CR)
For photographic images, CR is usually
below 2 for lossless, but can reach over
10 for lossy

Delta Modulation

Vector Quantization

Codebook Construction

Generalized Lloyd Algorithm

BTC

Bit Allocation

Zonal Coding

Threshold Mask

Image Compression Standards

Sequential DCT

Lossless Mode

JPEG Lossless Scheme

Progressive Encoding
The main idea of progressive
encoding is a gradual compression
using the priority of the pixels. First it
sends the coarse version of the
image to the receiver. Then the
additional information is sent so that
the quality of the image is
progressively refined.

Hierarchical Mode
This scheme uses the pyramidal data
structure that stores the image at
several different resolutions.

Summary

Summary

Das könnte Ihnen auch gefallen