digital image processing & pattern analysis (csce 563) image compression prof. amr goneid...
TRANSCRIPT
Digital Image Processing&
Pattern Analysis(CSCE 563)
Image Compression
Digital Image Processing&
Pattern Analysis(CSCE 563)
Image Compression
Prof. Amr Goneid
Department of Computer Science & EngineeringThe American University in Cairo
Prof. Amr Goneid, AUC 2
Image Compression
Definitions
Image Compression Models
Prefix (Huffman) Coding
Run-Length Coding
Bit-Plane Coding
Constant Area Coding
Lossy Compression
Standards
Prof. Amr Goneid, AUC 3
1. Definitions
Symbol:
A one-to-one representation of a single entity.
Alphabet:
A finite set of symbols.
Message:
A sequence of symbols.
Encoding:
Translating symbols to a string of bits.
Decoding:
The reverse.
Prof. Amr Goneid, AUC 4
Definitions (continued)
Coding Redundancy
Interpixel Redundancy
Psychovisual Redundancy
Lossless Compression
Lossy Compression
Prof. Amr Goneid, AUC 5
2. Image Compression Models
General ModelGeneral Model
Source Encoder
ChannelEncoder
Channel
ChannelDecoder
SourceDecoder
f(x,y)
g(x,y)g(x,y)
Prof. Amr Goneid, AUC 6
Source Encoder/Decoder
QuantizerSymbol
EncoderMapper
De-Quantizer
InverseMapper
g(x,y)
f(x,y)
Symbol Decoder
Prof. Amr Goneid, AUC 7
Source Encoder/Decoder
Mapper: e.g. FFT, DCT
Quantizer: makes use of psychovisual redundancy (e.g. scalar or vector quantization)
Symbol Encoder: e.g. Huffman, Run-length,
Also called redundancy encoder
Symbol Decoder: the reverse
Inverse Mapper: e.g. IFFT, IDCT
Prof. Amr Goneid, AUC 8
3. Prefix (Huffman) Coding
Terminology
Coding Efficiency & Redundancy
Variable Length Coding
Building The Optimal Merge Tree
File Compression
Prof. Amr Goneid, AUC 9
(a) Terminology
Binary Merge Tree:A binary tree with external nodes representing entities and internal nodes representing merges of these entities.Optimal Binary Merge Tree:The sum of paths from root to external nodes is optimal (e.g.minimum)Fixed and Variable Length Coding
Prof. Amr Goneid, AUC 10
Example: Coding Tree for 4-Symbol Alphabet (a,b,c,d)
abcd
ab cd
a b c d
0
0 1
Encoding:
a 00
b 01
c 10
d 11
Decoding:
0110001100
b c a d a
This is fixed length coding
1
0 1
Prof. Amr Goneid, AUC 11
(b) Coding Efficiency & Redundancy
di =Length of path from root to symbol (i) = no. of bits representing that symbol.
Pi = probability of occurrence of symbol (i) in message.
n = size of alphabet.
< L > = Average Symbol Length = 1 i n Pi di bits/symbol (bps)
For fixed length coding, di = d = constant, < L > = d (bps)
Is this optimal (minimum) ? Not necessarily.
Prof. Amr Goneid, AUC 12
Coding Efficiency & RedundancyThe minimum length (in bits) is called the Entropy defined as:
H = <L>min = 1 i n Pi log2 (1/ Pi) bpsWhen the probabilities Pi of n symbols are all equal, we have fixed length coding. In this case: H = log2 n (e.g. the 256 ASCII characters require 8 bits per symbol)When the probabilities in a given message are not equal, we could have H < log2 n (e.g. the message “aaaabbcc” in a 4-symbol alphabet has H = 1.5 bps)In this case, if we are using fixed codes of < L > = 2 bps, there will be a coding redundancy R = 1 – H / < L > 0 R 1The coding efficiency is: = 1 – R = H / < L > 0 1
Prof. Amr Goneid, AUC 13
Example4- Symbol Alphabet (a,b,c,d)
Message : abbcaada
Symbol(i) code pi -log pi -pi log pi
a 00 0.5 1 0.5
b 01 0.25 2 0.5
c 10 0,125 3 0.375
d 11 0.125 3 0.375
Entropy H = 0.5 + 0.5 + 0.375 + 0.375 = 1.75 (bps), < L > = 2 (bps)
= H / < L > = 1.75 / 2 = 0.875
R = 0.125
This is not optimal
Prof. Amr Goneid, AUC 14
(c) Variable Length Coding (Huffman Coding)
Only when all probabilities are equal that fixed length coding is optimal
To achieve optimality, use optimal binary merge trees to code symbols of unequal probabilities.
Huffman Coding: More frequent symbols occur nearer to the root
( shorter code lengths), less frequent symbols occur at deeper levels (longer code lengths).
Example:
a (50%) (0) , b (25%) (10) , c (12.5%) (110) , d (12.5%) (111)
< L > = ( 1* 0.5 + 2 * 0.25 + 3 * 0.125 + 3 * 0.125) = 1.75 (bps)
= H / < L > = 1.75 / 1.75 = 1.00 , R = 0.0
Prof. Amr Goneid, AUC 15
(d) Building The Optimal Merge Tree
Merge Tablesymbol prob symbol prob symbol prob symbol prob code
a 0.5 a 0.5 a o.5 abcd 1 0b 0.25 b 0.25 bcd 0.5 10c 0.125 cd 0.25 110d 0.125 111
Prof. Amr Goneid, AUC 16
Optimal Merge Tree for the Example
Symbols exist at leaves, i.e., no symbol code is the prefix of another symbol code.
abcd
bcd
cd
a
b
c d
01
0 1
0 1
Prof. Amr Goneid, AUC 17
Red 19
Black 17
Green 16
Blue 5
Cyan 4
Magenta 2
Yellow 1
Example: 8 x 8 image
Prof. Amr Goneid, AUC 18
Huffman code for the example
red 00
black 01
green 10
blue 111
cyan 1100
magenta 11010
yellow 11011
< L > = 2.34 bps
Compression ratio = 0.293
for 256 colors
Prof. Amr Goneid, AUC 19
(e) File CompressionVariable Length Codes can be used to compress files. Symbols are initially coded using ASCII (8-bit) fixed length codes.Steps:1. Determine Probabilities of symbols in file.2. Build Merge Tree (or Table)3. Assign variable length codes to symbols.4. Encode symbols using new codes.The Compression Ratio = < L > / 8
Prof. Amr Goneid, AUC 20
4. Run-Length Coding
Each row is coded as a sequence of lengths describing successive runs of black and white pixels.
Assume that the first run of each row is always white (which could have zero length)
The 2D version is the standard FAX coding
Prof. Amr Goneid, AUC 21
RL Coding Example
Run-Length for 2 rows
Row 1 : 0 7 2 3 1 4 3Row 2 : 5 5 4 6
Symbols can be coded using Huffman codeInefficient for high rate of 0 , 1 transitions
Prof. Amr Goneid, AUC 22
5. Bit-Plane Coding
Bit-Plane decomposition
For example for
8-bit gray level
0
1
7
Prof. Amr Goneid, AUC 23
Example ofBit Plane Decomposition
Prof. Amr Goneid, AUC 24
Bit-Plane Coding
Decompose image into bit planesEach binary plane is coded using binary coding technique (e.g Run-Length)Small changes in gray level produce frequent 0,1 transitionse.g. pixel(1) = 127 = 0 1 1 1 1 1 1 1
pixel(2) = 128 = 1 0 0 0 0 0 0 0Solution: Code planes using Gray-Code
Prof. Amr Goneid, AUC 25
Gray Code
Successive code words differ only by one bit
e.g. pixel(1) = 127 = 0 1 0 0 0 0 0 0
pixel(2) = 128 = 1 1 0 0 0 0 0 0
g(i) = a(i) a(i+1) i = 0 ,1 , .. ,6 g(7) = a(7)
g7 …... g0a7……..a0
Prof. Amr Goneid, AUC 26
6. Constant Area Coding
Four 3x3 blocks in binary bit plane, normally coded in 36 bits.Block Coding scheme:white 0, black 10mixed 11Resulting Code (14 bits):011(100010001) 100
Prof. Amr Goneid, AUC 27
7. Lossy Compression
Transform Coding
T(g) = FFT or DCT
SymbolEncoder
Symbol Decoder
T-1(G’)Mergef’(NxN)
g(nxn)f(NxN) T(g) G QTZR
G’Q
QG’
g’
(N/n)2
subimages
De-QTZR
Prof. Amr Goneid, AUC 28
Fidelity Criteria
Root-Mean-Square Error
erms = [(1/N2) x y [f ’(x,y) – f(x,y)]2]1/2
Signal-to-Noise Ratio
x y f ’(x,y)2
SNR = ___________________
x y [f ’(x,y) – f(x,y)]2
Prof. Amr Goneid, AUC 29
DCT Coding Example(1)
Image (I) 57x62 DCT(I)
Prof. Amr Goneid, AUC 30
Zigzag Mapping of 8x8 Block
1 2 6 7 15 16 28 29;
3 5 8 14 17 27 30 43;
4 9 13 18 26 31 42 44;
10 12 19 25 32 41 45 54;
11 20 24 33 40 46 53 55;
21 23 34 39 47 52 56 61;
22 35 38 48 51 57 60 62;
36 37 49 50 58 59 63 64
DC
Prof. Amr Goneid, AUC 31
Example(1) continued
|DCT(I)| Highest 25%
Prof. Amr Goneid, AUC 32
DCT Coding Example(2)
100 % Highest 43 %
Prof. Amr Goneid, AUC 33
Example(2) continued
Highest 10 % Highest 1 %
Prof. Amr Goneid, AUC 34
8. Standards
CCITTCommittee of the International Telephone and TelegraphRun-length with Variable Length Coding
JPEG (Joint Photographic Experts Group)DCT on 8x8 pixel regions. Variable length encoding.
Prof. Amr Goneid, AUC 35
JPEG
Five Steps:
1. Transform image to luminance/chrominance color space (YCbCr).
2. Reduce the color components (optional).
3. Partition image into 8 x 8 pixel blocks and perform the DCT on each block.
4. Quantize resulting DCT coefficients.
5. Entropy code the reduced coefficients.
Prof. Amr Goneid, AUC 36
JPEG
RUN-LENGTH CODE FOR ZERO VALUES AND HUFFMAN CODINGVARIABLE BIT LENGTH CODE FOR EACH COLOR BLOCK
DC
64 HARMONIC FREQUENCY VALUES DC = BACKGROUND BRIGHTNESS
V V V V V V V V V V V V V V V V V V V V V V V V V V V V V
DCQUANTIZATION, SELECT HIGHEST VALUES, ZERO OUT LESSER VALUES
V 0 V V 0 V 0 V V V0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DC value defines the overall background brightness63 harmonic frequency values define the block patternApplying a quantization threshold for lossy compressionHigh threshold = high compression ratio = low image qualityZero out all frequency values which are below the thresholdRun length coding defines a string of zeroes by a single numberHuffman coding uses variable bit length output code for each block