26
Binary Image Compression

Binary Compress

Embed Size (px)

Citation preview

Page 1: Binary Compress

Binary Image Compression

Page 2: Binary Compress

Contents

Run-length coding

Predictive coding

READ code

Block coding

Page 3: Binary Compress

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.

Page 4: Binary Compress

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

Page 5: Binary Compress

Methods for binary image compression

• Run-length encoding

• Predictive encoding

• READ code

• CCITT group 3 and group 4 standards

• Block coding

• JBIG, JBIG2

Page 6: Binary Compress

Run-length coding idea

• Pre-processing method, good when one symbol occurs with high probability or when symbols aredependent

• Count how many repeated symbol occur

• Source ’symbol’ = length of run

Example: …, 4b, 9w, 2b, 2w, 6b, 6w, 2b, ...

Page 7: Binary Compress

Run-length encoding: CCITT standard

Resolution:

Image: 1728*1,188

or 2 Mbytes

Transmission time: T=7 min

Page 8: Binary Compress

Run-length encoding: Example

RL Code

4 b ’011’ 9 w ’10100’2 b ’112 w ’0111’6 b ’0010’6 w ’1110’2 b ’11’

Page 9: Binary Compress

Run-length Huffman encoding: 0 n 63

...

Page 10: Binary Compress

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’

?

Page 11: Binary Compress

Predictive coding: Idea

• 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 1 1 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) Why 2?

Errors: 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 H=0.5 bit

Page 12: Binary Compress

Four-pixel prediction function

62.99 %

83.97 %

87.98 %

71.05 %

86.59 %

70.10 %

95.19 %

96.64 %

77.14 %

94.99 %

61.41 %

61.41 %

78.74 %

78.60 %

91.82 %

99.76 %

Page 13: Binary Compress

READ Code (1)

• Code the location of run boundary relative to theprevious row.

READ = ”Relative Element Address Designate”

• The READ code includes three coding modes:

o Pass modeo Vertical modeo Horizontal mode

Page 14: Binary Compress

READ Code: Principles

•If a1 before b2

•Vertical mode:

•Distance a1 and b1 less or equal to 3, send location of a1 with respect to b1, move a0 to a1

and continue encoding

•Horizontal mode:• Distance a1 and b1 is large, revert to 1-D technique and send length of white and black run

Page 15: Binary Compress

READ Code: Principles

•Pass code: • if b1 and b2 lie between a0 a1

• Transmitter informs receiver about the situation by sending code 0001

• location of a0 to the right below b2 – all pixels with same color

Page 16: Binary Compress

READ: Codes fo modes

wl = length of the white run bl = length of the black runHw = Huffman code of white run Hb = Huffman code of black run

(For Hufman codes see previous slides)

Page 17: Binary Compress

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

Page 18: Binary Compress

Horizontal mode (c1,c2)

Page 19: Binary Compress

Flowchart

Page 20: Binary Compress

READ Code: Example

vertical mode

010

reference line

current line

code generated

horizontal mode pass

code

vertical mode horizontal mode

-1 0 3 white 4 black +2 4 white 7 black-2

1 1000 011 0001 000011 000010 00011001001 1011

Page 21: Binary Compress

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.

Page 22: Binary Compress

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.

Page 23: Binary Compress

Hierarchical block encoding: (1)

Code: ’1’

Code: ’0111’

L=1

L=2

Page 24: Binary Compress

Hierarchical block encoding ()

Codes: 0011 0111 1000

Codes: 0111 1111 1111 11000101 1010

Totally: 1+4+12+24 = 41 bits

L=3

L=4

Page 25: Binary Compress

Hierarchical block encoding: ExampleImage to be compressed: Code bits:

1 0111 0011 0111 1000

x x

x x

0111 1111 11110101 1010 1100

x x x x

x x x x

x x x x

x x x x

x x

x x

x x

x x

x x

x x

x x

x x

x x

x x

x x

x x

1

0 1 1 1

0 0 1 1 0 1 1 1 1 0 0 0

0111 1111 1111 0101 1010 1100

1+4+12+24=41

Page 26: Binary Compress

CCITT Group 3 (G3) and Group 4 (G4)

• The RLE and READ algorithms are included in imagecompression standards, known as CCITT G3 and G4.

(used in FAX-machines).

Buffer

READ

RLE

0101101100...Run length

Boundary

Bits

Bits

Pixel

points