Image Compression
Image Compression
Image Compression
• 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
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)
units of information!
Redundancy(data vs info)
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
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
• 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
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:
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))
α 3 α 3 α 1 α 2 α4
Predictive Coding
LZW Coding
(addresses interpixel redundancy)
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)
Reconstructed
Error is high!
Original