FAX Image Compression - Haifacs.haifa.ac.il/~nimrod/Compression/Image/I1fax2009.pdf · MODIFIED...

38
FAX Image Compression Nimrod Peleg Update: May 2009

Transcript of FAX Image Compression - Haifacs.haifa.ac.il/~nimrod/Compression/Image/I1fax2009.pdf · MODIFIED...

FAX Image Compression

Nimrod PelegUpdate: May 2009

FAX: Historical Background

• Invented in 1843, by Scottish physicist Alexander Bain (English Patent No. 9,745 for recording telegraph, facsimile unit)

• Based on paper, saturated with electrolytic solution, changes its color when electric current passes through it

• Note that:– Telegraph, (Morse) : 1844– Telephone, (A.G Bell) : 1876

Pantelegraph, 1861

Facsimile technical progress• 1843: Bain’s Pendulum type• 1844: Telegraph (Morse) Entropy coding !• 1850: Rotating drum (England)• 1865: 1st commercial FAX (Caselli)• 1876: Telephone (Bell)• 1902: Optical scan• 1917: Teletype, AT&T• - 1968: many proprietary machines (AT&T,

RCA, Artzt, Teledeltos, Xerox, ......)

Facsimile technical progress (Cont’d)• 1968: CCITT Group 1 Rec.• 1976: CCITT Group 2 Rec.• 1976 - 1980: CCITT Group 3 Rec.• 1984: Group 4 Rec.• 1988: Error free G.3• 1991: ISO/IEC CD 11544 JBIG

• 2003: – 56Kbps Fax/Modem– 1.5Mbps ADSL/Cable

CCITT Group 1,2 (1968)Standardization for machines outside N. America:Parameter G.1 AM.6M G.2Lines/Min. 180 180 360Modulation FM FM VSB AM/PMCarrier Freq. 2100Hz ± 10Hz

White signal 1300Hz 1500Hz Max carrierBlack signal 2100Hz 2400Hz 26dB max. lower

Digital FAX• Run-Length (RL) developed by D.Weber,

removes redundancy from data:

New Line 100 white dots

RL Coding: W6,3,100,4,... First (non-standard) machine: DACOM (1974),with 4800bps modem over PTS (10 times slower

than Telex…)

CCITT Group 3 -T.4 recommendation (1980-88)

• V.29 Modem, 9600bps Standard Optional

Scan Direction: Left to Right, top to BottomScan Width (mm) 215 255 303Pels per Line 1728 2048 2432Horiz. Pel 8mm(203”)Vert. Pel 3.85(97.8) 7.7(195.6)Coding Modified H. Modified ReadData Modem v.27(ter) v.29bps 4800/2400 9600/7200

CCITT G.3 (1980-88) (Cont’d)

Signaling Modem v.21 v.27(ter)bps 300 2400mSec./Line 20 0,5,10,40Starting pel Always White # of Elements/Code Word 0 - 63 / 64-1728End-of-Line Code (EOL) 0000000000001End-of-Page Code 6 x EOL

G.3 Architecture

Optic Scanner(CCD)

A/DConverter

MH / MRCompression

Modem

ModemMH / MRDeCompression

ThermalPrinter

Receiver

Transmitter

PSTN (Analog network)

Computer created

Computer presented

Group 3 & Group 4

GROUP 3

•MODIFIED HUFFMAN METHOD (MHM) – Unidimensional codingmethod based on the coding of the lenght of alternate black and white

pixel runs using Huffman coding.

GROUP 4 (Also Group 3 Options)

•MODIFIED READ METHOD (MRM) – Bidimensional coding methodbased on the coding of the variations of the positions of tone transition pixels (black-white or white-black) in relation to the previous line; unidimensionalcoding may be used every k lines.

•MODIFIED-MODIFIED READ METHOD (MMRM) – Similar to MRMbut without periodic unidimensional coding.

G.3 Compression

• 5% - 20% of source (up to 95% comp.)• Modified Huffman Coding:

– Assume long White Runs between black pixels– White Runs can long complete line:(9 bits coding, meaning 192:1 compression)– 92 different codes: 28 groups of pX64 pixels,

and 64 short-runs of 0-63 pixels– 13 more codes for long runs (1792 - 2560)

White run length Code word Black run length Code word

0123456789

10111213141516171819202122232425262728293031

001101010001110111100010111100111011111001110100001110100000100000001111010011010110101010101101001110001100000100000101110000011000010001010000101011001001101001000011000000000100000001100011010

0123456789

10111213141516171819202122232425262728293031

000011011101011100110011001000011000101000100000010000001010000111000001000000011100001100000000101110000011000000000100000001100111000011010000000110110000000110111000001010000000001011100000011000000011001010000011001011000011001100000011001101000001101000000001101001

Huffman Codes

White run length Code word Black run length Code word

3233343536373839404142434445464748495051525354555657585960616263

0001101100010010000100110001010000010101000101100001011100101000001010010010101000101011001011000010110100000100000001010000101000001011010100100101001101010100010101010010010000100101010110000101100101011010010110110100101001001011001100100011001100110100

3233343536373839404142434445464748495051525354555657585960616263

000001101010000001101011000011010010000011010011000011010100000011010101000011010110000011010111000001101100000001101101000011011010000011011011000001010100000001010101000001010110000001010111000001100100000001100101000001010010000001010011000000100100000000110111000000111000000000100111000000101000000001011000000001011001000000101011000000101100000001011010000001100110000001100111

Huffman Codes Cont’d

hite run length Code word Black run length Code word

64128192256320384448512576640704768832896960

102410881152121612801344140814721536160016641728

11011100100101110110111001101100011011101100100011001010110100001100111011001100011001101011010010011010011011010100011010101011010110011010111011011000011011001011011010011011011010011000010011001010011010011000010011011

64128192256320384448512576640704768832896960

102410881152121612801344140814721536160016641728

000000111100001100100000001100100100000101101100000011001100000011010000000011010100000011011000000001101101000000100101000000010010110000001001100000000100110100000011100100000001110011000000111010000000011101010000001110110000000111011100000010100100000001010011000000101010000000010101010000001011010000000101101100000011001000000001100101

Make-up codes between 64 and 1728

Run length(black and white) Make-up codes

1792185619201984204821122176224023042368243224962560

000000010000000000110000000001101000000010010000000010011000000010100000000010101000000010110000000010111000000011100000000011101000000011110000000011111

Make-up codes between 1792 and 2560

Modified Huffman example

• Total pixel count: 599, MH: 27 bits,• Compression Ratio: 599/27=22.2 (~4.5%)

New Line

585 white dots

RL: 2W 5B 5W 2B 585W

MH: 0111 0011 1100 11 01101000 10100

Modified READ Coding • READ: Relative Element Address Designate:

exploits the correlation between successive lines• Element: A group of pixels of same color• Changing Element: An element with different

color from previous element• The position of every changing element is coded

relatively to a reference element in the current line or the reference line (above)

G.4 is a simplified version of G.3 in which only 2D coding is allowed

READ Coding example (Cont’d)

• If a couple of matching elements are positioned less than 3 pixels horiz. distance we code them in vertical mode

• If more than 3 pixels distance:– Pass Mode if the change in reference line– Horizontal mode if the change in current lineuse horizontal mode for next two changes in

current line and back to vertical mode (if possible)

READ: details

• Coding line:– a0: last pixel known to both encoder and decoder– a1: 1st transition right to a0 (known to encoder only)– a2: 2nd transition right to a0 (known to encoder only)

• Reference line– b1: 1st transition right to a0 location (opposite color)– b2: 1st transition right to b1

RC

a0 a1

b1 b2

a2

READ example 1 (Cont’d)

• b1 and b2 are between a0 and a1: this is a ‘Pass Mode’:the decoder knows that all the pixels to the right of a0 until below b2 are same color.

• So, the last known is changing to a0 and a new b1, b2 should be defined

RC

a1 a2a0

b1 b2

READ example 2

• In this case it can’t be Pass Mode.• since the distance between a1 and below b1 is no

more than 3 (1 in this case) - it is a ‘Vertical Mode’: a1 location is encoded relative to b1, and a1 becomes a0.

• If the distance is more than 3 pixels we change to ‘Horizontal Mode’: the distances (a0,a1) and (a1,a2) are encoded using Modified Huffman (MH)

RC

a0 a1

b1 b2

a2

Another Coding Example

• a0: Reference element• a1, a2, b1, b2,: Changing elements• b2 is to the right of a1, and the distance

between a1 and b1 is equal to 3 : its a vertical mode, and a new a0 assigned:

a0

b1 b2

a1 a2Next a0

A Coding Example (Cont’d)

• Once the compression mode is determined, a corresponding code can be formed:

Mode CodewordPass 0001Horizontal 001+M(a0,a1) + M(a1,a2)Vertical:

a1 below b1 1a1 one to the right of b1 011a1 two to the right of b1 000011...... .....a1 three to the left of b1 0000010

A more complicated example

V V P V V H V

RC

RC

Coding Mode

Scan Lines:

Changing Pels:

VPH

Black PixelWhite PixelChanging Position

Vertical ModePass ModeHorizontal Mode

:::

K-Factor• When distorted by noise pulse, errors are

made in the received copy.• To prevent from propagating down the

page, a MH coded line is sent periodically.• After one line is coded in 1-dimensional

mode, K-1 lines will be coded in 2-D mode: At normal resolution every second line (K=2), and at fine resolution K=4 (3 lines)

G.3 Enhancements (option)

• Error Concealment• Error Control• Dither Coding• RS-232 Interface• High Resolution• Small Page Size (A5, A6)• Non-Standard Operation

Group 4: CCITT T.6• Identical to T.4 with a slight difference: only

2-D mode is allowed (Called MMR).A Comparison of binary image coding (after [3]):

Source image* MH ** MR MMR JBIG

letter 20,605 B 31% 59% 68%

Sparse text 26155 B 37% 62% 71%

Dense text 133,705 B 23% 33% 48%

* Source images are of size: 4352x3072 dots (1 bit pixels)

** MH results in bytes, all other results are better than MH in x%

JBIG

• Lossless Compression.• Progressive Coding.• Sequential Coding.• Arithmetic Encoder/Decoder.• Resolution Reduction Algorithm• (optional, can be replaced).

Encoder Scheme

I D-1IDI D-2Resolution

reductionanddifferentiallayerencoding

Resolutionreductionanddifferentiallayerencoding

Lowest resolutionlayerencoder

ID-1 ID-2 I0

C0,D , C1,D, ... CS-1,D

C0,D-1, C1,D-1 , ... CS-1,D-1

C0,0 , C1,0 , ...CS-1,0

Resolution Reduction Technique

Creates low resolution images.Combines decimation and filtering in one action.Uses 9 high resolution and 3 low resolution pixels to determine color of target pixel.Preserves gray-levels achieved with halftoning.

JBIG Pro’s and Con’s

☺ Progressive (for binary images).☺ Better compression for images with up to ☺ 6 bit/pixel (Vs. JPEG)☺ Better compression than G3 and G4.

Slow and complicated (Vs. JPEG, G.3/4)Consumes memory resources and needs frame buffers.

Compression Comparison (in bytes)

#1 #2 #3 #4 #5 #6 #7 #80

10000

20000

30000

40000

50000

60000

70000

#1 #2 #3 #4 #5 #6 #7 #8

JBIG (3-line)G4-MMR

CCITT FAX reference images (#1 - #8)Original size: 513216 bytes

FAX ]reference images

Compression Comparison (Cont’d)

Typical results for:• Scanned text and line drawings:JBIG ~20-25% better than G4• Computer generated line-drawing:JBIG ~75% better than G4• Scanned dither halftones images:JBIG ~85%-90% better than G4

References:• McConnel, Bodson and Schaphorst, FAX: Digital

Facsimile Technology and Applications, Artech 1989

• K, Sayood, Introduction to Data Compression• R.Arps and T.Truong, Comparison of

International Standards for Lossless Image Compression. Proc. Of IEEE, 82:889-899, June 1994

• ITU-T (Former CCITT) Blue Book T.0-T.63, 1989, Recommendations T.4, T.6