1 / 38

Image Compression Binary Image Compression

Image Compression Binary Image Compression. Contents. Run-length coding Predictive coding READ code Block coding. Binary images. Binary images consist only of two colors, black and white. The probability distribution of the alphabet is often

aviva
Télécharger la présentation

Image Compression Binary Image Compression

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Image Compression Binary Image Compression

  2. Contents • Run-length coding • Predictive coding • READ code • Block coding

  3. Binary images • Binary images consist only of two colors, black and white. • The probability distribution of the alphabet is often • very skew: p(white)=0.98, and p(black)=0.02. • Moreover, the images usually have large homogenous • areas of the same color.

  4. Characteristics of binary images • Scanner resolution (fax machine): • a) 200*100 dpi (standard) • b) 200*200 dpi (high) • Image size: 1728*1188 = 2 Mbytes (standard resolution) • Transmission rate: 4.8 Kbit/s • Transmission time: 7 min

  5. Methods for binary image compression • Run-length encoding • Predictive encoding • READ code • Block coding • CCITT group 3 and group 4 standards • JBIG, JBIG2 (the next lecture)

  6. Run-length coding idea • Pre-processing method, good when one symbol • occurs with high probability or when symbols are • dependent • Count how many repeated symbol occur • Source ’symbol’ = length of run Example: …, 4b, 9w, 2b, 2w, 6b, 6w, 2b, ...

  7. Run-length encoding: CCITT standard Resolution: Image: 1728*1,188 or 2 Mbytes Transmission time: T=7 min

  8. Run-length encoding: Example RL Code 4 b ’011’ 9 w ’10100’ 2 b ’11 2 w ’0111’ 6 b ’0010’ 6 w ’1110’ 2 b ’11’

  9. Run-length Huffman encoding: 0  n  63 Terminating codewords (TC)

  10. Run-length Huffman encoding: n > 63 ? Examples: n=30w: code=’00000011’ n=94w=64w+30w: code=’11011 00000011’ n=64w=64w+ 0w: code=’11011 00110101’

  11. Predictive coding : Idea 1) Calculate prediction value: yi=f(neibourhood of xi). 2) Calculating the prediction error: ei= yi- xi. 3) Encode the prediction error ei.

  12. Predictive coding • Predict the pixel value on the basis of past pixel(s) • Send ‘0’ if prediction is correct, ‘1’ if prediction is not • correct. • Predictor for xi : yi = xi-1 • Prediction error: ei = xi-xi-1 • Example: alphabet S = {0,1} • Data: (0) 0 0 0 0 1 11 1 1 1 1 1 0 0 0 0  H=1.0 bit • Errors: 0 0 0 0 1 0 0 0 0 0 0 0 -1 0 0 0 • (If e < 0 then e = e+2) • Errors: 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0  H=0.5 bit

  13. Four-pixel prediction function

  14. Predictive model for grayscale images y=xi-xi-1 Histogram of the original image and Residual image Entropy: Ho= 7.8 bits/pel (?) Hr=5.1 bits/pel (?)

  15. Coding without prediction f0=8; p0=p=8/64 =0.125; f1=56; p1 =(1-p)=56/64=0.875 Entropy: H =-((8/64)*log2(8/64)+(56/64)*log2(56/64))=0.544 bits/pel

  16. Prediction for binary images by pixel above f p 16 16/64 48 48/64 Entropy: H =-((16/64)*log2(16/64)+(48/64)*log2(48/64))=0.811 bits/pel Wrong predictor!

  17. Prediction for binary images pixel to the left f p 1 1/64 63 63/64 Entropy: H =-((1/64)*log2(1/64) + (63/64)*log2(63/64)) =0.116 bits/pel Good predictor!

  18. Comparison of predictors: • Without prediction: H= 0.544 bits/pel • Prediction by pixel above: H = 0.811 bits /pel (bad!) • Prediction by pixel to the left: H=0.116 bits/pel (good!)

  19. READ Code (1) • Code the location of run boundary relative to the • previous row. • READ = ”Relative Element Address Designate” • The READ code includes three coding modes: • o Pass mode • o Vertical mode • o Horizontal mode

  20. READ Code: Principles • Vertical mode: • The position of each color change is coded with respect • to a nearby change position of the same color on the • reference line, if one exists. "Nearby" is taken to mean • within three pixels. • Horizontal mode: • There is no nearby change position on the reference line, • one-dimensional run-length coding - called • Pass code: • The reference line contains a run that has no counterpart • in the current line; next complete run of the opposite • color in the reference line should be skipped.

  21. READ: Codes fo modes wl = length of the white run bl = length of the black run Hw = Huffman code of white run Hb = Huffman code of black run (For Hufman codes see previous slides)

  22. READ code • There is an all-white line above the page, which used as the reference line for the 1st scan line of the page. • Each line is assumed start with a white pixel, which is ignored by receiver. • Pointer a0 is set to an imaginary white pel on the left of the coding line, and a1 is set to point to the 1st black pel on the coding line. • The first run length is | a0a1 |-1. • Pointers b1 and b2 are set to point to the start of the 1st and 2nd • runs on the reference line, respectively. • The encoder assumes an extra pel on the right of the line, with a color opposite that of the last pixel.

  23. Pass (a) and Vertical mode (b1,b2)

  24. Horizontal mode (c1,c2)

  25. Flowchart

  26. READ Code: Example

  27. Shortcoming of Huffman codes Alphabet: a, b. pa=p=0.99, pb=q=0.01 1) Entropy H1=-(p*log2(p)+q*log2(q))=0.081 bits/pel 2) Huffman code: pa=’0’, pb=’1’ Bitrate R1 = 1*p+1*q = p+q = 1 bit/pel! Make a new alphabet blocking symbols!

  28. Block Coding: Idea • Divide the image into blocks of pixels. • A totally white block (all-white block) is coded by ’0’. • All other blocks (non‑white blocks) thus contain at least • one black pixel. They are coded with a 1‑bit as a prefix • followed by the contents of the block (bit by bit in • row-major order) or with Huffman code. • The Block Coding can be applied to difference (error) • image for predictive coding approach.

  29. Block coding: n=2 New alphabet: ’A’=’aa’, ’B’=’ab’, ’C’=’ba’, ’D’=’bb’ pA=p2=0.9801, pB=pq=0.0099, pC=pq=0.0099, pD= q2=0.0001 1) Entropy: H2=-(0.9801*log2(0.9801) + 0.0099*log2(0.0099) + + 0.0099*log2(0.0099) + 0.0001*log2(0.0001))= =(0.0284+0.0659+0.0659+0.0013)/2= 0.081 bits/pel H2=H1 2) Huffman code: cA=’0’, cB=’10’, cC=’110’, cD=’111’ LA=1, LB=2, LC=3, LD=3 Bitrate R2 = (1*pA+2*pB+3*pC+3*pD)/2=0.515 bits/pel

  30. Block coding: n=3 ’A’=’aaa’ -> pA=p3 ’B=’aab’, ’C’=’aba’, ’D’=’baa’ -> pB= pC=pD=p2q ’E’=’abb’, ’F’=’bab’, ’G’=’bba’ -> pE= pF=pG=pq2 ’H’=’bbb’ -> pH=q3 Huffman code: cA=’0’, cB=’10’, cC=’110’, cD=’1110’ cE=’111100, cB=’111101’, cG=’111110’, cH=’111111’ Entropy H3? Bitrate: R3 = (1*pA+2*pB+3*pC+4*pD+6*(pE+pF+pG+pH))/3= = 0.353 bits/pel

  31. Block coding: n  pa=p=0.99, pb=q=0.01 Entropy Hn=0.081 bits/pel Bitrate for Hufman coder: n= 1: R1 = 1.0 bit 2 symbols in alphabet n= 2: R2 = 0.515 bits 4 symbols in alphabet n= 3: R3 = 0.353 bits 8 symbols in alphabet If block size n  ? Hn  Rn  Hn+1/n Problem - alphabet size and Huffman table size grows exponentially with number of symbols n blocked.

  32. Block coding: Example 2, n=1 pa=56/64 pb=8/64 1) Entropy H=-((56/64)*log2(56/64)+(8/64)*log2(8/64))=0.544 bits/pel 2) Huffman code: a= ’0’; b=’1’ Bitrate: R= 1 bit/pel

  33. Block coding: Example 2, n=4 pA=12/16 pB=4/16 1) Entropy H=-((12/16)*log2(12/16)+(4/16)*log2(4/16))/4=0.203 bits/pel 2) Huffman code: A=’0’, B=’1’ Bitrate R = (1*pA+1*pB)/4=0.250 bits/pel

  34. Compressed file size Model size n=1: Model size: pa, pb 21*8 bits n=2: Model size: pA, pB , pC, pD  22*8 bits n=k: Model size: {pA, pB , …, pK}2k*8 bits Compressed data size for S symbols in input file: R*S bits, where R is bitrate (bits/pel) Total size: Model size + R*S bits

  35. Hierarchical block encoding: Principle • In the hierarchical variant of the block coding the bit map • is first divided into b*b blocks (typically 16*16). • These blocks are then divided into quadtree structure of • blocks in the following manner: • If a particular b*b block is all-white, it is coded by ’0’. • Otherwise the block is coded by ’1’ and then divided into • four equal sized subblocks which are recursively coded • in the same manner.

  36. Hierarchical block encoding: (1) L=1 Code: ’1’ L=2 Code: ’0111’

  37. Hierarchical block encoding () L=3 Codes: 0011 0111 1000 L=4 Codes: 0111 1111 1111 1100 0101 1010 Totally: 1+4+12+24 = 41 bits

  38. Hierarchical block encoding: Example 1 0 1 1 1 1 0 0 0 1+4+12+24=41 0 0 1 1 0 1 1 1 0111 1111 1111 0101 1010 1100

More Related