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

Image Compression

Uploaded by

Monark Mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Image Compression

Uploaded by

Monark Mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 39

Image Coding and Compression

Image Compression

Reduce the amount of data required to represent a digital image.


Type:-
• Lossless
• Exact recreaction of original image (perfectly equal to original in terms of intensity
values)
• Information preserving
• Low compression ratios
• Eg: biometric, medical
• Lossy
• Not visually different but in terms of few intensity values
• Information loss
• High compression ratios
• Eg: transmission
Trade-off: information loss vs compression ratio
Compression
Ratio
Data Redundancy

• Data are the means to convey information; various amounts of data may be used to
represent the same amount of information
• Part of data may provide no relevant information: data redundancy, i.e., the amount of
data can be much larger expressed than the amount of information.
• Image coding/compression techniques can be designed by reducing or eliminating the
Data Redundancy and retaining information.
Example:
Types of Data Redundancy
Data compression attempts to reduce one or more of these redundancy types :-
• Coding Redundancy
• Interpixel Redundancy
• Interband Redundancy
• Psychovisual Redundancy

1. Coding Redundancy
Coding redundancy results from employing inefficient
coding schemes!
• Code: a list of symbols (letters, numbers, bits etc.)
• Code word: a sequence of symbols used to represent information (e.g., gray levels).
• Code word length: number of symbols in a code word; could be fixed or variable.
• To compare the efficiency of different coding schemes, we can compute the average
number of symbols Lavg per code word.
N x M image l(rk): # of bits for rk
rk: k-th gray level P(rk): probability of rk
Code 1: Average image size: 3NM

Code 2: Average image size: 2.7NM

Compression Ratio:
Redundancy:

2. Interpixel Redundancy
Interpixel redundancy results from pixel correlations (i.e., a pixel value can be reasonably
predicted by its neighbors).
auto-correlation: f(x)=g(x)

To reduce interpixel redundancy, some transformation is typically applied on the data.


3. Psychovisual redundancy
The human eye is more sensitive to the lower frequencies than to the higher frequencies in
the visual spectrum. Idea: discard data that is perceptually insignificant!
Measuring Information
• We assume that information is generated by a probabilistic process.
• Associate information with probability!
• A random event E with probability P(E) contains:-

Note: I(E)=0 when P(E)=1. If prob = 1, info is 0 as it is certain

How much information does a pixel contain?


• Suppose that gray level values are generated by a random process, then rk contains:

units of information!

Note: log is base 2


Average information content of an image:

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

Redundancy(data vs info)

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

image
1. First order estimate of H:

H = 1.81 bits/pixel
R = Lavg- H where Lavg = 8 bits/pixel
R = 6.19 bits/pixel
Note: log is base 2
2. Second order estimate of H:
Use relative frequencies of pixel blocks: find all unique pairs of pixel values in horizontal
rows. Now count their frequencies.

R = 6.75 bits/pixel

Differences between first-order(1.81) and higher-order entropy (1.25) estimates indicate


the presence of interpixel redundancy (i.e., need to apply some transformation to deal with
it). More redundancy was removed in 2nd order as amount of info per pixel reduced
Image Compression Model

• Preprocessing done before encoding to prepare image for encoding process


• Postprocessing done after decoding to eliminate some of the undesirable artifacts

Encoder
• Data Reduction: image data can be reduced by gray level and/or spatial quantization or
can undergo any improvement (like noise removal)
• Mapper: transforms data to account for interpixel redundancies. Map data into another
mathematical space where its easier to compress.
• Quantizer(only for analogue image): quantizes the data to account for psychovisual
redundancies. Taking potentially continuous data and putting into discrete form.
• Coding: Mapping the discrete data from quantizer onto code in an optimal manner.
• Symbol encoder: encodes the data to account for coding redundancies.
A compression algorithm may consist of all of these or few of these.

Decoder
Fidelity Criteria

• Used to determine which information can be removed and which is important.


• Provides metrics for determining image quality
• Can be used only for lossy compression, not for lossless as we preserve 100% in lossless.
Uncompressed Compressed Decompressed

The criteria can be:


1. Subjective: If large difference is acceptable or even small is unacceptable depends on use
case (based on human observers)
2. Objective: based on mathematically defined criteria
• Root mean square error (RMS)

• Mean-square signal-to-noise ratio (SNR)


Lossless Compression

• Calculate probability of
each pixel occurrence
• Most frequently occurring
pixel gets shortest code
word (reducing Lavg)
• Least frequently occurring
pixel gets longest code
word
Huffman Coding
• Variable length coding: addresses coding redundancy and yields smallest possible code word
length per source symbol.
• one-to-one correspondence b/w source symbols and code words (reversible without loss)

Huffman Encoding
Forward Pass:-
1. Sort probabilities per symbol (desc)
2. Combine the lowest two
probabilities
3. Repeat Step 1&2 until only two
probabilities remain.
Backward Pass:-
1. Assign code symbols going
backwards.
2. Trace the sum back to 2 nos and
append a 0 and 1 to the current
code word
3. Copy others (not lowest) as it is

• Lavg assuming binary coding:


Note: l(ak) is length of code word

• Lavg assuming Huffman coding:

Using Huffman coding only 2.2 bits required instead of 3


Huffman Decoding
• Decoding can be performed unambiguously using a look-up table.
• Eg: to decode code word: 010100111100
• We keep appending symbol until we find a match

Disadvantages
• For large alphabet size M requires large calculations.
• Requires knowledge of probabilities.
• Coding tables also needed to be sent.
• JPEG, MPEG etc have default Huffman coding tables.
Run-length coding (RLC)
• Addresses interpixel redundancy
• Reduce the size of a repeating string of symbols (i.e., “run”). Encode each “run” as (symbol,
count), for example:

• Using two bytes (assuming 0<=symbol, count<=255)


• Using Huffman or Arithmetic coding, by treating them as new symbols.
• Assuming that a message has been encoded using Huffman coding, additional compression
can be achieved using run-length coding.
• Eg:
Huffman encoded code: 010100111100
Runlength encoded: 010100111100 -> (0,1) (1,1) (0,1) (1,1) (0,2) (0,4) (0,2)
Arithmetic Coding
• Addresses coding redundancy
• Huffman coding encodes source symbols one at a time which might not be efficient.
• Arithmetic coding encodes sequences of source symbols to variable length code words.
• There is no one-to-one correspondence between source symbols and code words.
• Slower than Huffman coding but can achieve higher compression.

Arithmetic Encoding
• Map a sequence of symbols to a real number (arithmetic code) in the interval [0, 1).
α1 α2 α3 α3 α4

• The mapping is built incrementally (i.e., as each symbol arrives) and depends on the source
symbol probabilities.
Prob will be given or have to be calculated.
Initial subinterval starts with 0 and ends at 1.
For each interval:-
lower bound = previous upper bound
Upper bound = lower bound + prob

0.8

0.4

0.2
Bounds calculation:
Ub = lb + (prob(symbol) * overall(ub-lb))

The arithmetic code 0.068 can be encoded using Binary Fraction:


0.0068 ≈ 0.000100011 (9 bits)
Huffman Code:
0100011001 (10 bits)
Fixed Binary Code:
5 x 8 bits/symbol = 40 bits
Arithmetic Decoding Decode 0.572 with 5 symbols

α 3 α 3 α 1 α 2 α4
Predictive Coding
LZW Coding
(addresses interpixel redundancy)

• Requires no prior knowledge of symbol probabilities.

• Assigns sequences of source symbols to fixed length


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

• Included in GIF, TIFF and PDF file formats


Lossy Compression
• Transform the image into some other
domain to reduce interpixel
redundancy.
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 coeff De-quantized coeff


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 coeff De-quantized coeff


Effect of Quantization:
non-homogeneous 8 x 8 block (cont’d)

Reconstructed

Error is high!

Original

You might also like