Download presentation
Published byAubrey Harvey Modified over 9 years ago
1
Digital Image Processing & Pattern Analysis (CSCE 563) Image Compression
Prof. Amr Goneid Department of Computer Science & Engineering The American University in Cairo
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 Model f(x,y) Source Encoder Channel Encoder Channel g(x,y) Source Decoder Channel Decoder Prof. Amr Goneid, AUC
6
Source Encoder/Decoder
f(x,y) Mapper Quantizer Symbol Encoder g(x,y) Inverse Mapper De- Quantizer 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)
Encoding: a 00 b 01 c 10 d 11 Decoding: b c a d a This is fixed length coding abcd 1 ab cd 1 1 a b c d 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 & Redundancy
The minimum length (in bits) is called the Entropy defined as: H = <L>min = 1 i n Pi log2 (1/ Pi) bps When 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 1 The coding efficiency is: = 1 – R = H / < L > 1 Prof. Amr Goneid, AUC
13
Example Symbol(i) code pi -log pi -pi log pi a 00 0.5 1 0.5
4- Symbol Alphabet (a,b,c,d) Message : abbcaada Symbol(i) code pi log pi -pi log pi a b c 10 0, d Entropy H = = 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.125) = 1.75 (bps) = H / < L > = 1.75 / 1.75 = , R = 0.0 Prof. Amr Goneid, AUC
15
(d) Building The Optimal Merge Tree
Merge Table 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 1 a bcd 1 cd b 1 c d Prof. Amr Goneid, AUC
17
Example: 8 x 8 image Red 19 Black 17 Green 16 Blue 5 Cyan 4 Magenta 2
Yellow 1 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 Compression Variable 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 3
Symbols can be coded using Huffman code Inefficient 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 1 7 Prof. Amr Goneid, AUC
23
Example of Bit Plane Decomposition
Prof. Amr Goneid, AUC
24
Bit-Plane Coding Decompose image into bit planes
Each binary plane is coded using binary coding technique (e.g Run-Length) Small changes in gray level produce frequent 0,1 transitions e.g. pixel(1) = 127 = pixel(2) = 128 = Solution: 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 = pixel(2) = 128 = g(i) = a(i) a(i+1) i = 0 ,1 , .. ,6 g(7) = a(7) a7……..a0 g7 …... g0 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 10 mixed 11 Resulting Code (14 bits): 11( ) 10 Prof. Amr Goneid, AUC
27
7. Lossy Compression Q Q Transform Coding T(g) = FFT or DCT Symbol
Encoder f(NxN) QTZR T(g) G g(nxn) G’ (N/n)2 subimages Q f’(NxN) Merge T-1(G’) De- QTZR Symbol Decoder g’ G’ 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
; ; ; ; ; ; ; 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 CCITT Committee of the International Telephone and Telegraph Run-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 DC value defines the overall background brightness
64 HARMONIC FREQUENCY VALUES DC = BACKGROUND BRIGHTNESS V DC QUANTIZATION, SELECT HIGHEST VALUES, ZERO OUT LESSER VALUES V RUN-LENGTH CODE FOR ZERO VALUES AND HUFFMAN CODING VARIABLE BIT LENGTH CODE FOR EACH COLOR BLOCK DC value defines the overall background brightness 63 harmonic frequency values define the block pattern Applying a quantization threshold for lossy compression High threshold = high compression ratio = low image quality Zero out all frequency values which are below the threshold Run length coding defines a string of zeroes by a single number Huffman coding uses variable bit length output code for each block Prof. Amr Goneid, AUC
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.