ENEE63 Fall 2 Lecture-7 Introduction to Image Comresion htt://www.ece.umd.edu/class/enee63/ minwu@eng.umd.edu M. Wu: ENEE63 Digital Image Processing (Fall') Min Wu Electrical & Comuter Engineering Univ. of Maryland, College Park Review of Last Time -D transform of a vector Reresent an N-samle sequence as a vector in N-dimension vector sace Transform Different reresentation of this vector in the sace via different basis e.g., -D DFT from time domain to frequency domain Forward transform In the form of inner roduct Project a vector onto a new set of basis to obtain N coefficients Inverse transform Use linear combination of basis vectors weighted by transform coeff. to reresent the original signal 2-D transform of a matrix Rewrite the matrix into a vector and aly -D transform Searable transform allows alying transform to rows then columns M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [2] Review of Last Time (cont d) Reresentation with orthonormal basis Unitary transform Preserve energy, decorrelation, etc. Common unitary transforms DFT, DCT, KLT Which transform to choose? Deend on need in articular task/alication DFT ~ reflect hysical meaning of frequency or satial frequency KLT ~ otimal in energy comaction DCT ~ real-to-real, and close to KLT s energy comactability Today s addition: Haar Transform Construction of Haar functions Unique decomosition of integer k (, q) k =,, N- with N = 2 n, <= <= n- q =, (for =); <= q <= 2 (for >) e.g., k= (,), k= (,); k=2 (,), k=3 (,2) h k (x) = h,q (x) for x [,] h ( x) = h h ( x) = h k ( x) = N,, q 2 N ( x) = 2 N for x [,] / 2 / 2 q- q- 2 for x < 2 2 q- 2 q for x < 2 2 for other x [,] ower of 2 k = 2 + q reminder x M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [3] M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [4]
Haar Transform Haar transform H Samleh k (x) at {m/n} m =,, N- Real and orthogonal Transition at each scale is localized according to q 2 8 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 Comare Basis Images of DCT and Haar Basis images of 2-D (searable) Haar transform One examle of wavelets and and multiresolution concets NxN DCT basis images reflect transitions throughout the NxN image Ordered by frequency Haar basis images can reflect local transitions Ordered both by frequency and by satial location index M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [5] M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [6] Why Need Comression? Savings in storage and transmission multimedia data (es. image and video) have large data volume difficult to send real-time uncomressed video over current network Image Comression Part-. Basics Accommodate relatively slow storage devices they do not allow laying back uncomressed multimedia data in real time x CD-ROM transfer rate ~ 5 kb/s 32 x 24 x 24 fs color video bit rate ~ 5.5MB/s => 36 seconds needed to transfer -sec uncomressed video from CD M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [7] M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [8] 2
Examle: Storing An Encycloedia From Ken Lam s DCT talk 2 (HK Polytech) 5, ages of text (2kB/age) ~ GB => 2: comress 3, color ictures (64 48 24bits) ~ 3GB => 5: 5 mas (64 48 6bits=.6MB/ma) ~.3GB => : 6 minutes of stereo sound (76kB/s) ~.6GB => 6: 3 animations with average 2 minutes long (64 32 6bits 6frames/s=6.5MB/s) ~ 23.4GB => 5: 5 digitized movies with average minute long (64 48 24bits 3frames/s = 27.6MB/s) ~ 82.8GB => 5: PCM coding How to encode a digital image into bits? Samling and erform uniform quantization Pulse Coded Modulation (PCM) 8 bits er ixel ~ good for grayscale image/video -2 b ~ needed for medical images Reduce # of b for reasonable quality via quantization Quantization reduces # of ossible levels to encode Visual quantization: comanding, contrast quantization, dithering, etc. Halftone use b but usually usamling ~ saving less than 2: Require a total of.gb storage caacity if without comression Reduce to 2.96GB if with comression I(x,y) Inut image Samler Quantizer Encoder image caturing device transmit M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [9] M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [] Discussion on Imroving PCM Quantized PCM values may not be equally likely Can we do better than encode each value using same # bits? Examle P( ) =.5, P( ) =.25, P( 2 ) =.25, P( 3 ) =.25 If use same # bits for all values Need 2 bits to reresent the four ossibilities if treat If use less bits for likely values ~ Variable Length Codes (VLC) => [], => [], 2 => [], 3 => [] Use.75 bits on average ~ saves.25 b! Bring robability into the icture Previously use rob. distr. to reduce MSE of quantization Now use rob. distr. to reduce average # bits er quantized samle Entroy coding Idea: use less bits for commonly seen values How many # bits needed? Limit of comression => Entroy Measures the uncertainty or amount of avg. information of a source Definition: H = Σ i i log 2 ( / i ) bits e.g., entroy of revious examle is.75 Can t reresent a source erfectly with less than avg. H bits er samle Can reresent a source erfectly with avg. H+ε bits er samle ( Shannon Lossless Coding Theorem) Comressability deends on the sources Imortant to decode coded stream efficiently without ambiguity See info. theory course for more theoretical details M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [2] M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [3] 3
E.g. of Entroy Coding: Huffman Coding Huffman Coding (cont d) Variable length code assigning about log 2 ( / i ) bits for the i th value has to be integer# of bits er symbol Ste- Arrange i in decreasing order and consider them as tree leaves Ste-2 Merge two nodes with smallest rob. to a new node and sum u rob. Arbitrarily assign and to each air of merging branch Ste-3 Reeat until no more than one node left. Read out codeword sequentially from root to leaf PCM Huffman S S S2 S3 S4 S5 S6 S7.25.2.5.4.625.625.625.625.29.25.25.54.25.46. M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [5] M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [6] Huffman Coding: Pros & Cons Pro Simlicity in imlementation (table looku) For a given block size Huffman coding gives the best coding efficiency Con Need to obtain source statistics Imrovement Code a grou of symbols as a whole to allow fractional # bit er symbol Arithmetic coding Lemel-Ziv coding or LZW algorithm universal, no need to estimate source statistics Discussion: Coding a Binary Image How to efficiently encode it? Run-length coding (RLC) Code length of runs of between successive run-length of ~ # of between good if often getting frequent large runs of and sarse E.g., => (4) () (3) () (6) () () Assign fixed-length codeword to run-length Or use variable-length code like Huffman to further imrove RLC Also alicable to general binary data sequence with sarse (or ) M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [7] M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [8] 4
Probability Model of Run-Length Coding Assume successive occur indeendently w.. Prob. of getting an L runs of (L=,,, M) P( L ) = L (-) for <= l <= M- (geometric distribution) P( L ) = M for L=M Avg. # binary symbols er run S avg = Σ L (L+) L (-) + M M = ( M ) / ( ) Comression ratio C = S avg / log 2 (M+) = ( M ) / [( ) log 2 (M+)] Examle P =.9, M=5 S avg = 7.94, C =.985, H =.469 b Avg. run-length coding rate B avg = 4 bit / 7.94 ~.56 b Coding efficiency = H / B avg ~ 9% How to Encode Correlated Sequence? Consider: high correlation between successive samles Predictive coding Basic rincile: Remove redundancy between successive ixels and only encode residual between actual and redicted Residue usually has much smaller dynamic range Allow fewer quantization levels for the same MSE => get comression Comression efficiency deends on intersamle redundancy First try u(n) + u q ~ (n) _ e(n) Quantizer u q (n) Encoder Decoder M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [9] M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [2] Predictive Coding (cont d) Problem with st try Inut to redictor are different at encoder and decoder decoder doesn t know u(n)! Mismatch error could roagate to future reconstructed samles Solution: Differential PCM (DPCM) Use quantized sequence u q (n) for rediction at both encoder and decoder u q~ (n)= f( u q (n-), u q (n-2),, u q (n-m) ) Prediction error e(n) Quantized rediction error e q (n) Distortion d(n) = e(n) e q (n) u(n) u q ~ (n) + _ u q ~ (n) e(n) Quantizer Encoder Decoder What redictor to use? u q (n) + + u q (n) Summary Finish image transform Begin basics on image coding/comression PCM coding Entroy coding Huffman Run-length Predictive coding Next time: transform coding M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [2] M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [22] 5
Assignment Readings Jain s.-.3 Reference Bovik s Handbook Sec.5. ENE63 Course Project: Introduction Food for thoughts What redictors to use for image redictive coding? ros and cons Announcement st in-class exam will be given after Image Comression M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [23] M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [24] Toic: Video Coding and Processing Team roject 2 students er team A few 3-erson teams are allowed by instructor s ermission What to turn in finally? A video codec (encoder-decoder) Self-roosed art on video rocessing/analysis Ste-by by-ste Aroach [9-/] 3 Building Blocks (BB) ~ similar to assignment individual work should kee a big icture of the roject in mind [/2] Team-u and submit roject roosal [2/2] Project demo, resentation, and reort eer review Details will be announced soon First BB on image transform will be osted this weekend M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [25] M. Wu: ENEE63 Digital Image Processing (Fall') Lec7 Image Comression 9/2/ [26] 6