Title: Image Compression
1 DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF
JOENSUU JOENSUU, FINLAND
- Image Compression
- Lecture 5b
- Binary Image Compression
- Alexander Kolesnikov
2Binary 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.
3Characteristics of binary images
- Scanner resolution (fax machine)
- a) 200100 dpi (standard)
- b) 200200 dpi (high)
- Image size 17281188 2 Mbytes (standard
resolution) - Transmission rate 4.8 Kbit/s
- Transmission time 7 min
4Methods for binary image compression
- Run-length encoding
- Predictive encoding
- READ code
- CCITT group 3 and group 4 standards
- Block coding
- JBIG, JBIG2 (the next lecture)
5Run-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, ...
6Run-length encoding CCITT standard
Resolution Image 17281,188 or 2
Mbytes Transmission time T7 min
7Run-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
8Run-length Huffman encoding 0 ? n ? 63
...
9Run-length Huffman encoding n gt 63
?
Examples n30w code00000011 n94w64w30w
code11011 00000011 n64w64w
0w code11011 00110101
10Predictive 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 ? H1.0 bit - Errors 0 0 0 0 1 0 0 0 0 0 0 0 -1 0 0
0 - (If e lt 0 then e e2)
Why 2? - Errors 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0
0 ? H0.5 bit
11Four-pixel prediction function
12READ 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
13READ 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.
14READ 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)
15READ 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.
16Pass (a) and Vertical mode (b1,b2)
17 Horizontal mode (c1,c2)
18Flowchart
19READ Code Example
20Block 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.
- (see also Lecture 2)
21Block Coding Huffman codes for k0, 1
22Block Coding Huffman codes for k2
23Block Coding Huffman codes for k3, 4
24Hierarchical block encoding Principle
- In the hierarchical variant of the block coding
the bit map - is first divided into bb blocks (typically
1616). - These blocks are then divided into quadtree
structure of - blocks in the following manner
- If a particular bb 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.
25Hierarchical block encoding (1)
L1
Code 1
L2
Code 0111
26Hierarchical block encoding ()
L3
Codes 0011 0111 1000
L4
Codes 0111 1111 1111 1100
0101 1010
Totally 141224 41 bits
27Hierarchical block encoding Example
1
0
1
1
1
1
0
0
0
0
0
1
1
0
1
1
1
14122441
0111
1111
1111
0101
1010
1100
28CCITT Group 3 (G3) and Group 4 (G4)
- The RLE and READ algorithms are included in
image - compression standards, known as CCITT G3 and
G4. - (used in FAX-machines).
29CCITT Group 3 (G3)
- Every k-th line is coded by RLE-method and
- the READ-code is applied for the rest of the
lines. - The first (virtual) pixel is white
- EOL code after every line to synchronize code
- Six EOL codes after every page
- Binary documents only
30CCITT Group 4 (G4)
- All lines are codes by READ
- The first reference line (above image) is white
- EOL code after every line to synchronize code
- Six EOL codes after every page
- Option for grayscale and color images
31G3 and G4 Results
Resolution Low (200?100) High
(200?200) Scheme G3 G4 G3 G4 Bits
per pel 0.13 0.11 0.09
0.07 Seconds 57 47 74 61
7 min ? 1 min
32Comparison of algorithms
33Contents
- Run-length coding
- Predictive coding
- READ code
- Block coding
- G3 and G4