• No results found

Efficient software implementation of the JBIG compression standard

N/A
N/A
Protected

Academic year: 2019

Share "Efficient software implementation of the JBIG compression standard"

Copied!
123
0
0

Loading.... (view fulltext now)

Full text

(1)

Rochester Institute of Technology

RIT Scholar Works

Theses

Thesis/Dissertation Collections

1993

Efficient software implementation of the JBIG

compression standard

Craig M. Smith

Follow this and additional works at:

http://scholarworks.rit.edu/theses

This Thesis is brought to you for free and open access by the Thesis/Dissertation Collections at RIT Scholar Works. It has been accepted for inclusion in Theses by an authorized administrator of RIT Scholar Works. For more information, please [email protected].

Recommended Citation

(2)
(3)
(4)

Table

of

Contents

Abstract

ix

1

Introduction

of

Compression Concepts

1

1.1

Compression

of

Binary

Images

2

1.2

Basic Information

Theory

3

1.3

Elias

Coding

8

1.4

Arithmetic

Coding

12

2

Description

ofthe

JBIG Image Compression

Standard

1 6

2.1

Purpose

of

JBIG

16

2.2

Sequential

vs.

Progressive

Processing

18

2.3

Resolution

Reduction

20

2.4

Prediction

21

2.4.1 Differential Layer Typical Prediction 22

2.4.2 Lowest Resolution Typical Prediction 23

2.4.3 Deterministic Prediction 24

2.5

Probability

Estimation

27

2.6

Adaptive Templates

30

2.7

Arithmetic

Coding

31

3

Optimizing

JBIG

Software

32

3.

1

An Efficient Algorithm for

Building

JBIG

Contexts

33

3.1.1

Building

ColumnsofThreePixels 34

3.1.2

Building

Common Context Words 36

3.1.3

Using

TablestoBuild Reordered JBIG Contexts

39

3.2

Encoding

Both Differential Layer Lines in

One Pass

40

3.3

Moving Efficiently

through

Solid

Areas

42

(5)

3.3.2

DifferentialLayer Typical Prediction in

Solid Areas

45

3.3.3

Arithmetic

Coding

in Solid Areas

(Sequential

Mode

Only)

48

3.4

Fast Deterministic Prediction

51

3.5

Removing

the

SWTCH

from the

Probability

Estimation

52

4

Results

56

4.1

Implementation

of

Software

56

4.2

Performance

ofthe

JBIG Algorithm

58

4.3

Comparison

of

JBIG

and

CCITT

Group

3

61

4.4

Effect

of

Image Noise

on

Compression Times

63

4.5

Halftone Images

67

5

Conclusions

70

(6)

Appendices

Appendix A

Block

Diagrams

ofthe

JBIG

Compression

Algorithm

75

Appendix

B

Routines

for

Reordering

JBIG

Tables

77

B.1

Reordering

Resolution Reduction Tables

77

B.2

Reordering

Deterministic

Prediction Tables

78

Appendix

C

Test Images

81

C.

1

Original Test Images

81

C.2

Example

of

Resolution Reduction

for

Progressive

Transmission

90

C.3

Examples

of

Images

with

Random Noise

96

C.4

Examples

of

Noisy

Images

after

Filtering

103

(7)

List

of

Figures

Figure

1

Formation

of a

digital

Image

2

Figure 2

General

Information Source

4

Figure

3

Example

Pixel

context

(or neighborhood)

for

a

4th

order

Markov

Source

7

Figure 4

Example

of recursive

probability interval

subdivision

in Elias

coding.

9

Figure

5

Alignment

of

the

arithmetic

coding

registers

13

Figure 6

Four

phases of

high

resolution pixels

1 9

Figure 7

Resolution Reduction

of an

image

20

Figure

8

Context

for Resolution Reduction

21

Figure

9

Context

for

differential layer

typical prediction

22

Figure 1 0

Context for Deterministic

Prediction

25

Figure 1 1

Encoding

contexts for the

lowest

resolution

layer

27

Figure 12

Encoding

contextsfor differential

layers

28

Figure 13

Structure

of

probability

estimation

29

Figure 14

Pixels

stored as a column ofthree pixels per

byte

34

Figure

15

Code fragment for

columnizing

pixels

35

Figure 16

Code

fragment for

building

common context words

36

Figure 17

Pixel

order

for

common context words

37

Figure

18

Examplecode

fragments for

combining

high

and

low

resolution

context words

39

Figure

19

Bit

orderof

probability

estimation context

for differential layer

encoding (Phase

3)

39

Figure

20

Software

example

for

processing

two

lines in

one pass

41

Figure 21

Efficient resolution reduction

in

solid areas

44

Figure 22

Efficient

typical prediction

in

solid areas

47

(8)

Figure

24

Efficient deterministic

prediction

52

Figure 25

Improved

structureof

probability

estimation

54

Figure 26

Module Diagram for

the

JBIG Compressor

56

Figure 27

The

effect of

image

noise on

JBIG

compression speed

for

progressive and sequentialtransmission

65

(9)

List

of

Tables

Table

1

Number

of

deterministically

predictable states

in the default DP

tables

25

Table

2

JBIG

executiontimeson a

VAXstation

4000/60,

in

seconds

58

Table 3

JBIG

executiontimeson a

Sun Sparc

2,

in

seconds

59

Table 4

JBIG

execution timeson a

Sun

Sparc

1

0,

in

seconds

59

Table 5

JBIG

execution timeson an

Amiga

3000,

25MHz

68030,

in

seconds ..

.,

60

Table 6

JBIG

compression ratios

for

test

images

61

Table 7

Comparison

of compression ratios

for

binary

image

compress

algorithms

62

Table 8

Comparison

of execution times

for

binary

image

compression

algorithms on a

Sun

Sparc

2

63

Table 9

Effect

of

image

noise on

JBIG

compression

for

the

CCITT image

set.. 64

Table 1 0

Effect

of

removing

image

noise on

JBIG

compression

(CCITT Test

Set)

66

Table

1 1

JBIG halftone

execution times on a

Sun

Sparc

2,

in

seconds

67

Table 12

JBIG halftone

compression ratios 67

Table

13

Comparison

of

halftone

compression ratios

for

binary

image

compression algorithms

69

Table 14

Comparisonof

halftone

compression execution times

for

binary

(10)

Abstract

JBIG

is

a new

binary

image

compression standard that

is designed

tohandle

both

text

andhalftoned documents. It

significantly

outperformsthe

CCITT

Group

3

and

Group

4 standardsespecially on

halftoned

documents.

The JBIG

standard is based on an arith

metic encoder, and it

features

adaptive probability estimation, adaptive templates, and

three different types ofprediction. It also allows eithersequential or progressivecom pression of

image

data.

A brief discussion of

information

theory

is given as it applies to image compression. The JBIGalgorithmis

described,

and severaltechniquesaredevelopedtoefficiently im plementthe algorithmin software. Themost importanttechniques include an efficient

scheme for

building

the context that are required, and

taking

advantage of large all-white or all-black regions of

images

by designing

very efficient loops for processing

those areas. Other techniques are also

discussed,

such as, efficient implementation of deterministicprediction,andanimprovedmethodfor

handling

theconditional exchange condition.

Timing

information is given for the final implementation on several plat

forms. The JBIG algorithm is compared with the CCITT

Group

3 and

Group

4 algo
(11)

1

Introduction

of

Compression Concepts

Within digital computer equipment,

information is

represented as a series of symbols

that are encoded as

binary

numbers.

Almost

any information can be represented this

way

including

character

based

datasuch as reports and computerprograms,

databases

of numbers representing scientific

information

or accounting

information,

and digital im

ages. Informationof this type can be stored in several ways, but the storage space is

often costly. Inaddition,theinformationcanbetransmittedfromone placeto another,

butwhenlargeamounts ofdataare

transferred,

itcantakea

long

time.

Toovercometheproblemsofstorage andtransmission

time,

itisoften usefulto convert

the information into a more compact representation. The resulting data requires less

storage andcanbetransmitted muchmore quickly. The processofconvertingthedata is often called

"data

compression."

Whenthe datarepresents apicture, the processis

knownas "image

compression."

The purpose ofthis chapter

is

to explain the concepts ofimage compression that are

necessary to have an understanding ofthe JBIG (Joint Bi-level Image experts

Group)

compression standard [1]. Before this can be accomplished, it is important to under

standwhy compressionofdigital imagesisuseful.

Next,

afew basicconcepts ofinfor

mation

theory

will be introduced. Thiswillbefollowed

by

adiscussionof animpracti

cal but instructionalencodingtechniqueknown as Elias coding [2].

Lastly,

arithmetic

codingwill be introduced. Arithmetic coding is analgorithmthatsolvesthe shortcom

ings

ofEliascoding, anditistheheartoftheJBIGstandard.
(12)

1.1

Compression

of

Binary

Images

Ina greatmanyapplications

it

isusefultousenumbersina computertorepresenta pic

ture orimage. This canbe

done

a number of

different

ways. In general, an original

scene ordocument

is

sampled at

discrete locations

by

ananalogsensorthatiscapable of

sensing the brightness of the image within a sample as

illustrated

in figure 1. Each

sample,or pixel(short forpictureelement)

is

thenconvertedtoa numberthatrepresents

the

brightness

ofthe image within the sample. The number ofbits used to represent

each pixelcan range anywherefrom 1 to 16. In many applications,thepixelsarestored

as an 8-bit quantity so thatthenumbers are intherange of0to255. In many business

_c

JlIIiI&k,*.

t~ ^ ^mmwmw

,*

r^ W^^MMMM mm

^ ft?f:?

n

pi

Mt

M

55>

m :::;!

IB

I :^J

iHH**?*:::*::: ::

%\

ts

8Hli

:|::S JK5J MW$' ;*

^

/

/

Original Image

Sampled

Image

saHSaBWaSBBaa

Sensor

Electronics

Assigna numberbased

on averagebrightnessof

-*. thesample.

Generally

between

0

and255.
(13)

applications,where

images

are generally comprised ofblack and white text documents

each pixel

is

storedas a 1-bitnumber. These 1-bit

images

areknownas

binary

images.

Anexample oftheuseof

binary

images

ina

business

application

is

afacsimilemachine.

Atypical FAX machine scans an

8.5

x 11 inch sheet of paper and generates a 1728 x

1

100

pixelimage. The resulting

image

contains 1,900,800pixels. SincemostFAXma

chines transmit data through a phone line at

9600

bits/second,

it would take about 3

minutes and20 secondsto transmit the entireimage. Formost

documents,

however,

it

is

possibleto compressthe image to 1/1 0th of

its

originalsize orless. This

is

accom

plished through the use of standard FAX compression algorithms.

As

a result, most

documentscanbetransmittedin 20secondsorless.

Another application in which

binary

images are common is in

binary

printers such as

laserprinters. Sincemostlaserprintersprint300 dotsperinchormore, afullpageim

age requires 8,415,000pixels. Inotherwords, a standard

high-density

PC

floppy

could

only holdonefullpage

image,

Ifthe images arecompressed,

however,

it ispossibleto

storeasmanyas 10-20 full-page imagesona single

floppy

disk.

1

.2

Basic Information

Theory

To have anyunderstandingoftheunderlyingconcepts ofimagecompressioningeneral,

and the JBIG standard in particular, it is necessary to be aware of some of the funda

mental concepts ofinformationtheory. Inthis section, afewofthebasic conceptswill

be discussed

briefly

and informally. The foundationforthis

theory

was developed

by

Shannon

[3]

in 1948. Foramore complete introductiontoinformation

theory

as itre

lates to image compression see Rabbani and Jones [4]. For a thorough discussion of

backgroundand uses ofinformation

theory

see refs. [5-6].
(14)

A

binary

image is

one example of asource of

information.

When it

is

sentto alaser

printer, each

binary

pixel represents

information

for the printer. The pixel tells the

printerwhethertoprint ablack dot at a specificlocation or not. Anotherexample of a

sourceofinformation is Englishtext. Inthiscase,thereader examineseachcharacterin

the textand extractsinformation from it.

In general, it

is

possible to

define

an

information

source,

5,

that generates a series of

symbols asshown in figure 2. Eachsymbol emitted

by

S ispartofafixedfinite alpha betof sizen,soS={si, ^ >

s

}

, andtheprobabilityofanysymbol,s-,inthe alpha

bet is aknown fixedvaluepis,). Ifeach symbol released

by

the source is statistically

independent of allother symbols released

by

S,

thenS is knownas a Discrete

Memo-rylessSource

(DMS)

[4].

Tounderstandtheinformationcarried

by

thesesymbols,considerapersonreceivingthe

symbols from a DMS. Whenreceiving symbols, the receivermight guess that the in

coming symbol willbethehighest probabilitysymbol. Ifhereceivesthesymbolheex

pected,heisnot surprised. Inotherwords,thesymbolcarriedhttle information. Onthe

other

hand,

ifthe receiver receives alow probability symbol,he is verysurprised. The

low probability symbol represents an event that was not expected, so it carries much

more information. Ingeneral,it istrue thattheamount ofinformationcarried

by

a sym bol

is

inversely

relatedtotheprobability ofthe symbol. Iftheinformationcarried

by

a

Source S

+

s?c

*b'

(15)

symbol

^

is

encoded

by

a

binary

alphabetforusein adigital system,

it

is given

by

the

equation

I(s.)

=-log2p(5f)

(1)

Since

the

DMS

generates symbols with a

known

probability, the average

information

per symbol canbecalculated

by

summingtheinformationgenerated

by

eachsymbolin

the alphabet weighted

by

theprobability ofthe symboloccurring as given

by

the equa

tion

H(S)

=

jy(Si)I(Si)

=-Yj>(Si)log p(st)

(

2

)

The quantity

H(S)

is knownastheentropyof sourceS. Itrepresentstheaverage amount

ofinformationthat the source,

5,

can generate. Itis auseful quantity because it repre sentsthe averagetheoreticallimitof algorithms thatencode thesymbolsusing a

binary

alphabet.

According

toShannon's noiseless sourcecoding theorem,nouniquely

decod-ablecode canhaveanaveragelength lessthatH(S).

As an example, consider aDMS generating bits for a

binary

image,

S =

[ 0,

1

}

.

Any

two symbols generated

by

the source are statistically

independent,

andtheprobabilities ofthe twooutput symbols arefixed. Ifthe twosymbols areequallyprobable,i.e.p(0) =

p(l)=

0.5,

then

by

usingequation

2,

theentropyofthesource

is

calculatedtobe

1.0

bit per pixel. Thismeans that

trying

to compressanimage generated

by

thesource would

be fruitless becausetheentropy ofthesourceis equalto thenumber ofbits inthe sym

bol sequence without compression. Iftheprobabilities ofthe twosymbols areunequal,

however,

the average amountofinformationper symbol would

be lower

and compres

sion wouldbepossible. Considera

binary

DMSwherep(0) =0.95

andp(l)= 0.05. In this case, according to equation

2,

theentropyofthe source is

0.29

bitsper pixel. This
(16)

means that compressing an

image

generated

by

the source could

be

a useful step be

cause

it

shouldbepossibletocompresstheimagetoabout athirdof

its

original size.

While

this example

is

usefulfor

illustrating

theconcept ofentropy, it

is

limited

because

typical informationsources are not statistically

independent.

Imagine a personreading

Englishtext one character atatime. If he sees thestring

'exampl',

he caneasily guess

with ahigh degreeofaccuracythat thenext character

is

an 'e'. Inthiscase, the Vcar

ries

very little information

because

thereaderknowsthat theprobabilityof an

V is

un

usually high basedon knowledgeoftheprevious symbols. In a similarmanner, itcan

be shown thatpixels in animageare statisticallyrelatedto theirneighbors.

Therefore,

theDiscrete Memoryless Source isnotanaccuratemodelformostimage data.

A better model for image informationis aMarkov Source [4]. An m orderMarkov

Source is a source in which theprobability ofoccurrence of a symbol

is

conditionally

dependenton m previous symbols.The probabilityof asymbol,s-is denotedas

p( sAS) where i=

1,

2,

...,n and

S

isavectorof mprevioussymbols

Sinceeach ofthem previous symbolsinthe

S

vectorhasn possiblevalues, anm order

Markov sourcehas

nm

possible states. Withineach state, theMarkov sourceis similar

to a DMS inthateach ofthen possible symbols hasafixedprobability.

Therefore,

the

entropyofasingle state oftheMarkov source,

SM,

isgiven

by

H(SM)

=-Yp(Si\

S)log

p(Si\

S)

(

3

)

i=l

for 1 <M<nm. TheoverallentropyoftheMarkovsourceisthesum oftheentropies of

eachstatetimes theprobabilitythat thestatecan occur

H(S)

=
(17)

It

is important

tonotethat theentropyof a sourcethatismodeled as aMarkovsource

is

alwaysless thanorequal to the entropyof a sourcethat

is

modeled as a DMS. This is

because

the Markov source takes advantage of the local

information

to make an im

proved prediction ofthe emitted symbols. As a result, on average,the symbols carry

less

information.

Whena

binary

image ismodeled as an m orderMarkovsource,theprobabilityofeach

pixel

is

dependenton mpreviouslytransmittedpixels.

Typically,

thepixels are selected

to

be

the m pixels closestto thepixel ofinterest. These nearbypixelsthat are usedto encode apixel are known as thepixel's context or thepixel's neighborhood. Figure 3

showsatypicalcontextfor a4 orderMarkovmodelinwhich thevalues ofpixelsXq,

Xj,X2,and x? formthevector

S.

While the Markov model is a significant improvement over the Discrete Memoryless

Source,

it still has two drawbacks.

First,

the complexity of the encoding algorithm

grows quickly as m gets larger becausethe number of possible states grows exponen

tially. Since

binary

image data has onlytwopossiblesymbolsin itsalphabet,thesizeof the context can be 10 or 12 pixels, as used

by

the JBIG algorithm, without unusually large memoryrequirements.

Secondly,

theimprovementsupplied

by

theMarkovmodel

is dependent on

knowing

the conditionalprobabilities to more accurately predict each

pixel. It

is

not generally true,

however,

that the conditional probabilities used in a

Previously

Transmitted

Pixels

Pixel

Context

Figure

3

Example Pixel

context

(or

neighborhood)

for

a 4th order

Markov

Source

(18)

Markov

model are thesame

for

all

binary

images.

In

fact,

theconditional probabilities

can change

dramatically

from

image

to

image.

To

overcome this problem, the JBIG

standard uses an adaptive

probability

estimate technique that allows the algorithm to

"learn"

the conditional probabilities for each

image.

This mechanism for this will be

explainedinsection2.5.

To summarize,theinformation content of a set of symbols

has

been described interms

of entropy. It

has been

assertedthattheentropyof a source can

be

calculatedbasedon a

statistical model of the generated symbols. It has also been

implied

that a sequence of

symbols generated

by

aninformationsource canbeencodedusinga

binary

alphabetinto

a

data

streamthatis approximately the same size as theentropyofthedata.

Therefore,

ifaninformationsourceismodeledtocreate anaccurate andbiased probabilityestimate

for predictingsymbolsbasedon alocalcontextofeachsymbol,theentropy of a source

can bereduced,

thereby

reducing the size ofthe output

binary

data.

Nothing

has been

saidabouthowthe symbols are encodedtogeneratethiscompressedoutputdatastream.

In

fact,

there are severalwellknown and simple algorithms for encoding symbols such

as Huffman coding

[7]

andrun-lengthcoding

[8]

thatare oftenused. Thesealgorithms

usevariable length

binary

codestorepresentone ormore source symbols. While these

techniques are simpletouse,

they

are notincluded intheJBIGstandard, andwillnotbe

discussed here. Within

JBIG,

the estimated probabilities ofeach symbol are encoded

using arelativelynewtechniqueknownas arithmetic coding. This is basedon anolder,

but impractical encodingalgorithmknownasEliascoding.

1.3

Elias

Coding

The technique known as Elias coding was introduced

by

Elias

[2]

as an algorithm for
(19)

re-quiredto encode a sequence of symbols

is

close to the entropy ofthe sequence.

The

drawback

ofthe technique is that it

is

not

implementable

for

image

compression be

cause it requires theuseofextremely largeregisters.

Regardless

of

its

implementation

limitations,

it

is instructional to understand ofthe

basic

concepts ofElias coding as a

basis

for understandingarithmeticcodingwhichwill

be discussed

insection1.4.

In Eliascoding, astringof symbols generated

by

asource,

S,

isencoded as a

binary

real

numberintherange of

[0, 1)

by

recursively subdividing probability intervals. Figure 4

shows agraphicalrepresentationofthis typeofsubdivision. The entire initialregionis

divided

into

two

intervals

proportionaltotheprobabilities of

0

and1. Whenasymbol

is

encoded,

its

subinterval is selected andproportionally subdividedforthe nextsymbol.

Thiscontinuesuntiltheentirestring isencoded.

Tobemoreprecise,consider aseries of

binary

symbolstobeencoded inwhich0 isthe

most probable symbol and has a probability of occurrence equal to p. 1 is the least

probable symbolandhas aprobability of occurrence equaltoqor1 - p. To

encode one

1.0

0.5

0.0

1

0

01

00

001

000

0001

0000

Symboltobecoded:

0

0 0

Figure

4

Example

of recursive

probability

interval subdivision

in Elias

coding.
(20)

ofthese symbols, the real numberrange

[0, 1)

is

subdivided

into

two

intervals, [0,

p)

representing the symbol

0,

and

fp, 1)

representing the symbol 1. If the symbol

0 is

coded,then theinterval

[0,

p)

is

subdivided again

into

regionsthatare proportionaltop

2 1

andq,namely

[0,

p

)

for

0,

and

[p

,p) for 1. If

instead

of

transmitting

thefirst symbol

as a

0,

the

first

symbolhad beena

1,

then thenewintervalwould

have

been

[p,

1),

andit

would have been subdivided into regions proportionaltop and q,

[p,

p+qp) for

0,

and

[p+qp,

1)

for 1. Thisprocedure ofrecursively

dividing

a subinterval intotwonew

sub-intervalsthatareproportionalto theprobabilities ofthesymbols

being

transmitted

is

re

peated for each symbol that is to be transmitted until the the entire message is sent.

Fromtheaboveexample,the

following

characteristics canbeseen:

After

transmitting

two symbols,the interval

[0.0,

1.0)

could have been subdivided

into one offourpossible intervals. In general, after

transmitting

n symbols the in

itial intervalcouldhave beensubdividedintooneof 2n

possibleintervals.

Noneofthepossibleintervalsoverlaps anyotherintervalatanypoint.

Thesubintervals covertheentire original rangeof

[0.0,

1.0).

For ninput symbols are

being

transmitted,the originalintervalof

[0.0, 1.0)

will be

subdividedin suchaway,thateverypointintheoriginalintervalwillbe associated

withexacdyone ofthefinalpossible subintervals.

Afterencoding n symbols, a finalsubintervalis selected. This subintervalcanbe de

scribed

by

the value ofthe first point inthe interval and the width ofthe interval (the

distance to the firstpoint in the next interval). The width ofthis final

interval,

w, is

given

by

theequation

v =

f[p(Si)

(

5

)

(21)

th Wherep(s-

)

is

the

probability of the i symbol in the string. The reasonthat this

is

important is

thatw

is

exacdyequalto the

joint

probabilitythatthe entirestringwill oc

cur. Basedon the discussion in section

1.2,

it

should

be

clear that the entropy ofthe

entirestringgenerated

by

source5 is

/5=-log2w

(6)

Once the final subinterval is selected, it can be uniquely identified

by

encoding any

point withinthesubinterval as a

binary

fraction. This

is

done

by

creatinga

binary

num--1 -2

ber,

b-ibj-.- that is interpretedasferx2 +bj^2 + .... A decoderthatreceives this

faction can

identify

the subinterval that contains this point, and therefore, completely

decodetheentirestring.

To determinethe bestchoice ofpointstoencode,thevalue ofthe

beginning

oftheinter

valisencodedandthe first

|7e 1

bitsofthe

binary

fractionareused,where

11

represents

the ceiling function. The resulting fractionrepresents the shortest possible

binary

code

to transmit theinformationofthestringandmustbewithinthefinalsubintervalbecause

w^lM

(7)

So

far inthis discussionofEliascoding,it has beenassumedthat theprobabilitiesp and

qare fixedandglobally known

by

boththeencoderanddecoder. Asseenintheexam

pleof aMarkov source in section 1.2,

however,

theentropyofa set ofdatacanbe low

ered

by

using alocal contexttomake betterpredictions of eachnewsymbol. Ifthe in

formation source is modeled as a Markov source, the probabilities that are used to

subdivide each interval must change from symbol to symbol

depending

on the current

Markov state. This added complication does not change anything inthe previous dis

cussion. In general, as

long

as the probabilities used for each symbol are causally
(22)

known

by

boththeencoderand

decoder,

the

Elias

codingalgorithmcouldoptimallyen

code anduniquely

decode

anystring.

The majordrawback of theElias algorithmisthat encodinga stringofarbitrary length

requires

infinite

precision registers. When encoding a

binary

image consisting of mil

lions ofpixels,registers that are severalmillionbits

long

couldberequiredto storethe

locationofthe

beginning

oftheintervalandthecurrentwidthoftheinterval. Thisprob

lem and others related to it are overcome

by

a compression technique known as

arithmetic coding.

1.4

Arithmetic

Coding

Arithmetic coding

[9-13]

is arelatively newencodingtechnique that isthecentral cod

ing

algorithmfortheJBIGcompression standard. While it is similarinconcept toElias

coding, it overcomesthe infiniteprecision problems. This is accomplished

by

using a

rescalingprocedurethat slides afixedprecision windowonthe infiniteprecisionregis

tersofEliascoding.

Inthis section,abriefdescriptionoftheJBIGarithmeticencoding algorithmisgivento

introducethebasicconcepts andpropertiesofthealgorithm. Fora moreprecisedefini

tionofthealgorithm seetheJBIGspecification[1]. Formorebackgroundontheimple

mentation of arithmeticcoding algorithms,itisusefulto study awelldocumentedarith

meticencoding algorithmdeveloped IBM knownastheQ-coder [14-16].

Foran arithmeticcoder, afixednumber ofbits is allocatedfor encodingtheprobability

of asymbol. In

JBIG,

16 bits are allocated. Two registers ofthis depth are required,

one to

keep

track ofthewidthofthe current subinterval

(

A

),

and oneto

keep

trackof

the bottomof the subinterval

(

C

). Theseregisters define the current subinterval ex
(23)

A

register)

falls

belowone

half,

bothregisters are

doubled

repeatedlyuntiltheAregister

is

abovethe onehalflevel. This scalingprocessis knownasrenormalizationandit ef

fectively

slidesbothregistersdownthearithmetic axis ofthetwoEliasvalues as shown

in

figure 5 untilthe first 1 bit inthefractionalrepresentation oftheElias interval

is

the

highorderbit inthe arithmeticAregister. The bits shifted out oftheC register arethe

bits

that aretransmittedas part oftheencodeddatastreamwithoneexception whichis

knownasthecarrypropagation problem.

The carry propagation problem iscaused

by

the factthat the value ofthe

beginning

of

theElias subinterval will alwaysstaythesameorincrease. When it

increases,

thevalue

ofthe arithmeticCregister can overflow. Theresult ofthe

binary

overflow willbethat

all l'sabovetheCregister willbe flippedtoO'sand thefirst 0 beforetheCregisterwill

be flipped to a 1. In general, this carry problemcan be handleda couple ofdifferent

ways. The JBIG algorithmkeepsthelast outputbytethatcontained azero andacount

ofthenumber of"all

1"

bytes (255

's)

thathaveoccurred since. When anoverflowoc

curs,thelastbyte containingazerois incrementedandtransmittedand the255 bytesare

transmittedas0 bytes.

EliasIntervalWidth: 0000 ... 0000

A- Register

0000

lxxxxxxxxxxxxxxx

EliasIntervalStart: xxxx ... xxxx

C- Register

0000

XXX XX XXXX XX XX XXX

Figure

5

Alignment ofthe arithmetic

coding

registers
(24)

Another important

concept tounderstand aboutthe arithmetic coder

is

the factthat

it is

computationallyefficient. When encodinga

binary

symbol, themostprobable symbol

will be encoded ahighpercentage ofthe time. Whenthis occurs, theA registerisre

duced

by

the size ofthe

least

probable subinterval. The exactsize oftheleastprobable

subinterval

is

theproduct ofthe currentinterval size,

A,

andtheprobability oftheleast

probable symbol,q.

Since

themultiply

is

undesirable,

it is

avoided

by

replacing Awith

the statistical average of

A,

which

is

a constant.

By

usingthe statistical average of

A,

the

following

approximationismadetocalculatean estimate oftheleastprobableinter

val,for everypossible valueofq

qXA~qXa =

qe

(8)

whereais theaverage overtheprobability

density

of

A,

and

qg

istheresultingestimate

of the least probable subinterval size. Sincethe normalizedvalue ofA is bounded be

tween0.5 and

1,

thevalue ofAcanbereplaced

by

awithout

introducing

alarge error.

Since q is known for everyvalue ofq,it canbestoredinatable andfoundwithoutthe

need for a multiply. As a result, the only required operation when encoding a most

probable symbolistheupdatefortheAregistergiven

by

A<-A-qe

(9)

Whentheleastprobable symbol isencodedtheAand

C

registers are changed asfollows

C+-C+A-qe

A

-qe

Eventhoughtheapproximationoftheq intervalcansimplifythearithmeticcalculations

without

imposing

alarge coding

inefficiency,

itdoescauseone anomaly.

Since

theesti

mationofthe q intervalis independentofthecurrent interval size,whenthe

interval, A,

(25)

larger

than the most probable subinterval.

This

can cause a

fairly

large

inefficiency.

Since

this condition canbe causally detected

by

a

decoder,

itcanbe corrected

by

both

the encoder and decoder

by

using the least probable subinterval to encode the most

probable symbol andusing the most probable subintervalto encode the leastprobable

symbol. This strategy

is

knownas conditional exchange and

it is

used

in

theJBIGarith

metic encoder.

(26)

2

Description

of

the

JBIG Image

Compression

Standard

In this chapter, a general description of the JBIG compression standard will be given.

This is not intendedto be a complete definition ofthe standard.

Instead,

each ofthe

components ofthealgorithmwillbe discussedsothat thereader

has

anunderstandingof

theissues and complexities relatedto the algorithm. Withthis understanding, thereader

should be aware ofthe need to

develop

efficient techniques for

implementing

the full

algorithm.

This discussionisprovidedas an introductionto the optimization stepsdiscussed in the

next chapter. Sincetheseoptimizationsonly dealwithissues in aJBIGcompressor,the

details ofthedecompressorare notdiscussed here. For information abouttheJBIG de

compressor and a more detailed description ofthe JBIG compressor, the reader is re

ferredto theJBIGspecification[1].

2.1

Purpose

of

JBIG

WorkonJBIG (Joint Bi-level Image Experts

Group)

began in 1988. Itspurpose wasto

define astandard,CCITT T.82andISO

11544,

for compressing

binary

image data fora

wide rangeofapplications. These applicationsincludesuch areas as

facsimile,

audiog-raphicteleconferencing,andimage databases. To fulfilltherequirements ofthese appli

cations andmany more,thealgorithmneededtobe flexibleenoughtoperform well over

awide range ofimagetypes and

imaging

systems.

Prior to

JBIG,

theprimary

binary

image compression standards in the world were the

CCITT

Group

3

[17]

and

Group

4

[18]

standards. These standards are reviewed and
(27)

one

dimensionally

encoderuns of consecutive white and blackpixels oneveryk line

ofthe

image.

Betweentheone

dimensionally

encoded

lines,

the

lines

are processed

by

encoding differences between twoconsecutive

lines

using atechniqueknown asModi

fied

READ (Relative Element

Address

Designate).

Since

the Huffman codes used

by

these standards were designed specifically for textbusiness

documents,

the algorithms

perform wellonthat typeofdocument. Halftoned

images, however,

have

distinctly

dif

ferentcharacteristics fromtextdocuments. Asaresult, halftoned images are not com

pressedwell

by

CCITT

Group

3

and

Group

4. In

fact,

the result ofusing

Group

3 or

Group

4 on ahalftoned image is normallya larger filethan the original, becausethese

algorithms cannot adaptto thelocalstatistics ofahalftoned image.

They

often expand

thedocumentinsteadofcompressing it.

JBIGwas developedtobeasignificant improvementover

Group

3 and

Group

4. Spe

cifically, it was desired that the JBIG algorithm provide the

following

improvements

overtheprevious standards:

1. provideimprovedcompressionfortextandlineartdocuments (seesection

4.3),

2. providesignificant compressionofhalftoneddocuments (seesection

4.3),

and

3. providethe abilityto transmitimagesprogressivelyaswellas sequentially (see sec

tion2.2).

To accomplish these goals, it was necessary to

develop

an algorithm thatwas signifi

cantly more complex than

Group

3

or

Group

4. This extra complexity ispossible be

cause of advancesin integratedcircuit

technology

andmicroprocessorperformance.
(28)

2.2

Sequential

vs.

Progressive

Processing

In many

image

processingapplications,an

image is

processed atfullresolutionfrom left

to right and from

top

to bottom in a single pass.

This

type ofprocessing

is

knownas

sequential processing. CCiTT

Group

3

and

Group

4 are examples of sequential com

pression algorithms. Sequential applications are normally simpler andrelatively inex

pensive to implement because it is not necessary to store an entire image in a page

buffer. The disadvantageof sequential compression algorithms isthat image datamust

beprocessed atfull resolution

before

auser can viewthe image. Sincethis can take a

significant amountoftime, it isnotoptimalfor many applications.

Inother applications,it can beuseful to transmitalow resolution version of an image

that can be displayed to the user almost immediately.

Increasingly

higher resolution

versions ofthe image aretransmitted sothat the image displayedtothe user is steadily

improved. This type of processing is known as progressive processing. Progressive

transmissionofimages isusefulfortworeasons:

1. Improved userinteraction: Since arepresentationofthefull image ispresentedto

auserveryquickly,ittakesmuchlesstimefortheusertorecognize andtherespond

to the image. If the user

is

interested inthe

image,

the user can wait for the full

imagetobetransmitted. Ontheother

hand,

iftheuser

is

notinterested inthe

image,

it would be possible to terminate thetransmissionwithout waiting. This

feature is

very important in image

browsing

applications where a user

is

searching though a

long

listof availableimages.

2.

Supporting

peripherals with

differing

resolutions: Images can be compressed

andstored in animage database and still used on avariety of peripherals at several

different resolutions. For

instance,

animage couldbe extractedfroma

database

for
(29)

ver-sion ofthe

image. The

same

image

could

be

printed at appropriate resolutions on a

300

DPIprinterora600 DPIprinter.

The disadvantage

of progressivealgorithms

is

that

they

require a pagebuffertostorethe

entireimage. This addsto thecost andcomplexityofthesystem.

Thealgorithm

defined

by

theJBIG standard can operate both sequentiallyand progres

sively. In addition, JBIGprovides a mode

known

as progressive-compatible sequential

mode. In this mode, an

image

is

divided

into horizontal sections called stripes. The

stripe is

decomposed

into therequired resolutionlayers and compressed as inprogres

sivemode. Theadvantageofthismodeisthatit onlyrequiresenoughmemorytobuffer

a stripe instead of the entire image. The compressed data for progressive and

progressive-compatible sequentialmodesis exactlythesame; it is simplystoredinadif

ferentorder. As aresult,

images

canbe storedinanimage database andtransmittedin

progressive mode to a CRT or in progressive-compatible sequential mode to a

binary

printer.

Thechoice of progressive orsequentialprocessing is dependentontheneeds ofthe ap

plication. It usually has very little effect on the overall compression rate ofan

image,

although progressiveprocessing doesrequiremoreprocessingtime

because

each ofthe

resolutionlayersmustbecompressed.

Whenprogressiveprocessing is used, anew low resolutionpixel is created for each 4

high resolution pixels. Figure 6 shows how this is normally represented notationally.

Figure

6

Four

phases of

high

resolution pixels
(30)

The

circle represents alowresolution pixel andthefour squares representthefourhigh

resolution pixels associatedwith it. Thepositionofthehighresolution pixel relativeto

thelowresolution pixelis knownasthespatial phase of thehighresolution pixel.

2.3

Resolution Reduction

Forthe JBIG algorithmto compressprogressively, it is first necessarytocreate each of

thelowresolution images.

To

create alow resolution

image,

ahighresolutionimage is

processed

by

an algorithmthat creates anewimagethat is halftheheight andhalfthe

width ofthe high resolution image. This process is repeated for each new resolution

that isneeded. Figure 7 illustratesthisprocess fortworeductions. Eachoftheseimages

is

thencompressed. A decompressor begins

by

decoding

thelowresolutionimage and

builds upto thedesired highresolutionimage.

The JBIG specification defines a default resolution reduction algorithm, although it is

possibletouse acustom algorithmtodothereduction..

Half

Resolution

Quarter

Resolution

Full

Resolution

(31)

The defaultresolution reduction algorithm uses atable to generate new low resolution

pixels so that theimplementation

is

efficient. It

is based

on a filterthat

is

designedto

preservethe average

density

ofanyarea.

Some

exceptionsto the filter designare made

to the table to improve thequality ofthe

resulting

low resolution images. The excep

tionsaremadeto

improve

theabilityofthe algorithmtopreservesedges,

lines,

periodic

patterns andditherpatterns. Pixels intheneighborhood ofthenewlowresolution pixel

are usedto indextheresolution reductiontable. Theorder ofthepixelsisshownin

fig

ure 8. Examplesoflowresolutionimagesareshownin Appendix C.2.

(>

r* 7

T

6

/^

5

V

1

3

9)-

-w-\

1

2

iyo

Figure

8

Context for

Resolution Reduction

2.4

Prediction

The JBIGstandard usesthree differentalgorithms topredict pixels. One forthelowest

resolutionlayerand twofordifferential layers (all layers butthelowestresolution). If

one or moreofthese algorithmsdetermines that apixelispredictable, thenitisnoten

coded because itcan bepredicted

by

the decoder. Each of thesepredictionalgorithms

canbeenabledordisabled

depending

onthedesired complexityofanimplementation.

Two oftheseprediction algorithms,one forthelowest resolution

layer,

and one for all

other

layers,

are known as typical predictors.

They

are called

"typical"

because

they

predict eventsthatare

typically

true, butnotalwaystrue. Atthe

beginning

of each

line,

apseudo-pixelisencodedto tell thedecoderwhether or nottheconditionistrue forthe

(32)

entireline. Ifthe conditionis

true,

then the algorithmcan predictpixels; otherwise,the

algorithm

is inactive

forthatline.

The

third prediction algorithm is known as

deterministic

prediction. This algorithm

uses aknowledgeof the resolution reductionto

determine

whenonlyone value

is

possi

ble forapixel.

2.4.1

Differential

Layer Typical Prediction

Thepurpose ofdifferential layertypicalprediction

(DTP)

is

to predict solid areas of an

image. The algorithm works on the assumption that if all ofthe pixels in a three

by

three neighborhood of a low resolution image are the same color, then the four high

resolutionpixels associatedwith the centerlow resolution pixel are the same color as

the neighborhood. Figure

9

illustrates thepixelsusedinthis assumption. Whilethisis

not alwaystrue, it isvalid most ofthetime. When differential layertypicalpredictionis

enabledtheassumptionistestedfortwolinesat atime todetermine if itisvalidforthat

pairoflines(two linesareusedbecauseallfour highresolutionpixelsaretested). Ifthe

assumptionis true,then thelines are saidtobetypical. Apseudo-pixelisthenencoded

(33)

at the

beginning

ofthe

first line

to tell the

decoder

whether or not the assumption

is

valid.

Whena pair ofimage

lines

is foundto be

typical,

itmeansthat this is a solidarea, and

all ofthepixels can

be

skipped. The decoderwillknow howtogeneratethepixelsjust

by

readingthevalue ofthepseudo-pixel. Sincemostdocumentscontain alarge amount

of solid area

(especially

white

background),

many ofthepixels inthedocument canbe

skipped. As a result, software

implementations

ofthe algorithmwill run muchfaster.

Thisistheentirepurpose oftheDTP algorithm.

Ingeneral, differential layertypicalpredictionhas very little effect onthe compression

performance oftheJBIG algorithm. In

fact,

enablingthisfeatureoften reducesthecom

pression ratio slighdy. The reason forthis is thatthepixels that are skipped carry al

mostno information (which is whythe DTP assumptionis normally valid).

Removing

these pixels has almostno effect ontheoverall entropyofthedocument.

However,

for

eachpairoflines anewpseudopixelis encoded. Theprobabilities associated withthis

pseudo-pixelare muchlessbiasedthan theskippedpixels, andtherefore, carrymore in

formation. Asaresult,the totalentropyofthedocumentdoesnot change significantiy.

2.4.2

Lowest Resolution Typical Prediction

The algorithm usedfortypicalprediction inthe differentiallayer assumesthepresence

ofalowerresolution image. Whenthe lowestresolution layer

is

encoded (orthe only

resolutionlayerforsequentialprocessing), aseparate algorithmisneeded. Inthiscase,

JBIG defines alowest resolutionlayertypicalpredictionalgorithm (also knownas

base

layertypical prediction or

BTP)

that simplytests two consecutive

lines

to

determine

if

they are exactly the same. Ifthe lines are found tobe the same, a pseudo-pixel

is

en

codedtotransmitthe

information,

andtheentireline

is

skipped with nofurther
(34)

ing. Ifthe

lines

are notthe same,thenthe pseudo-pixel

is

encoded

differently,

andthe

rest ofthe

line is

processed normally.

Typicalprediction

is

most useful for

processing

blank

lines

within the image. Forthis

reason ahighpercentage ofthepixelsinmost simple

business

documents donot needto

be

processed. As with differential layer typical prediction, this greatly improves the

speedof asoftware

implementation,

but is has

little

effectonthe compressionratiosof

thealgorithm.

2.4.3

Deterministic Prediction

Thepurpose of

deterministic

prediction

(DP)

istoremove thenecessityofencodingre

dundant information betweenalowresolutionimageand ahighresolutionimage. Since

the low resolution image must be similar in appearance to the high resolution

image,

there are cases wherehigh resolution pixelscanbe

identified

as

having

onlyonepossi

ble value. This canbe done becauseaknownalgorithmisusedtodotheresolution re

duction. As an example ofwhythis isvalid, consider a simple resolutionreduction al

gorithm that will create a black low resolution dot whenever two or more high

resolution dots areblack. Ifin a givenarea, thelowresolutionpixel iswhite, and one

black highresolution pixelis

decoded,

thenall oftherestofthepixelsmustbewhite. If

anyoftheother pixels were

black,

then thelowresolution pixel wouldhave been black.

Whilethisexampleassumesaverysimpleresolutionreductionalgorithm,thebasiccon

ceptcanbeappliedfor anyreduction algorithm. In

fact,

forthedefaultresolution reduc

tion algorithm, most images contain a significant number ofpixels that are predictable

by

thedeterministicprediction algorithm.

The deterministicprediction algorithmistabledrivensothatitcanbe

implemented

effi

ciently. Separate tables areused for eachofthe four high resolution pixels associated

(35)

Figure

10

Context

for

Deterministic

Prediction

thatwere used

by

theresolution algorithm. Infigure

10,

thepixelsthatareusedtobuild

the

index

are shown alongwiththeorderinwhichthebitsare placedinthe index. The

pixels numbered

8, 9, 11,

and12arethepixels

being

predicted. Foreachpixel,onlythe

previouslytransmittedpixels areused.

Specifically,

forpixel

8,

theindex isconstructed

frompixels

0-7,

forpixel

9,

the index is constructed from pixels

0-8,

forpixel

11,

the

index is constructed from pixels

0-10,

and forpixel

12,

the index is constructed from

pixels 0-11. The JBIGstandarddefinesthefour deterministicpredictiontables thatwill

work withthedefault resolution reductionalgorithm. Inthese

tables,

alargenumber of

theentriesareforpredictable pixels. Table1

defines

thenumberof context states possi

ble foreachpixelandhow manyofthesestates represent predictablepixels.

Target

Pixel

Number

of

Context

States

Number

of

States

with

Predictable Pixels

8 256 20

9 512 108

11 2048 526

12 4096 1044

Table

1 Numberof

deterministically

predictable states

in

the

default

DP tables
(36)

It

is

also possibleto transmit a set of custom DPtables as a part of the image header

defined

by

the standard. This is required ifa non-standard resolution reduction algo

rithm is

used.

The

main purpose of

deterministic

prediction

is

to

improve

the compressionperform

ance ofthe algorithm. Even though DPpredicts only avery few pixelsrelative to the

large

number predicted

by

typicalprediction, it

has

a muchlargereffect on theoverall

compressionratio. To understandwhythisisthecase, considerthepixels that are pre

dicted

by

thedeterministicpredictionalgorithm.

Many

ofthepixelspredicted

by

DPdo

nothave

highly

skewedprobabilities. Inotherwords,the pixels predicted

by

DP carry

more informationthan the TPpixels, so more bitswould be required to encode them.

Sincethesebits nolongerneedto be transmitted, and no extrainformationneeds tobe

encoded as in the typical prediction algorithm, the compression ratio improves. The

(37)

2.5

Probability

Estimation

Within the

JBIG

standard probabilities are conditionallyestimatedbased on agroup of

pixels in the neighborhood ofthe current pixel.

This is

similarto the Markov model discussed insection 1.2. One ofthe problemswith aMarkov model

is

that the condi tionalprobabilitiesthatare usedarenotconsistentfrom imageto image. To overcome thisproblem,theJBIG standard

defines

a method ofadaptiveprobabilityestimation so thatitcanlearnthecorrectprobabilities asitprocessesanimage

Within

JBIG,

a neighborhood of 10pixels is defined around the pixel

being

encoded.

These 10pixels aredesignedtobethe 10pixels most correlatedwiththecurrent pixel. There are sixdifferent encoding contextsdefined in JBIG for different encoding condi tions. Thesecontexts aregraphicallyrepresentedin

figures

11 and 12. Ineachcontext, there isapixel markA. Thepurpose ofthispixel willbe discussed insection2.6.

X

X

X

X

X

X

X

X

X

Two Line Context

X

X

X

X

X

X

X

A

X

X

7

Three

Line

Context

Figure

1

1

Encoding

contexts

for the lowest

resolution

layer.

(38)

When

encoding

thebase

layer,

therearetwopossibleencodingcontexts, atwolinecon

text,

and athreeline context. The JBIG standard suggeststhatthetwolinecontextwill

allow softwareto runsomewhatfasterwhilethe three linecontext will improvetheen

coding

by

about5%.

When encoding the differential resolution

layers,

there arefour different contexts that

areused. Thechoice of context

is

dependentontheposition(orphase)ofthehighreso lutionpixel

being

encodedrelativetoits corresponding lowresolution pixel. Thevalues

X

J

IX

J

\x

)

[

X

Phase

2

Phase

3

(39)

ofthe 10pixelsintheneighborhood arecombinedwiththetwobitvalue ofthephaseof

thepixeltoforma 12bitcontext. Withineach resolutionlayer (andalsowithineachbit

planeformultibit

images),

the algorithmkeeps trackofthecurrentmostprobable sym

bol

(MPS)

andthecurrentprobabilitystate

(ST)

for everycontext.

The

standard

defines

aprobabilityestimation statetablewith

113

possible states. Foreachstate inthe

table,

an estimationoftheleast probable symbol subintervalwidth

(LSZ)

isstored. LSZ is a

16 bitrepresentation ofthevalueq defined inequation

8

on page 14. Alsoincluded in

the state tableisthe nextprobability estimation stateto beused fora contextwhenthe

encoded valueisthemost probablesymbol

(NMPS),

andthestate tousenext whenthe

least probable symbol is encoded (NLPS). The probability estimation state changes

eachtime a renormalization

is

performed. The last value in the state table also is the

value, SWTCH that is used to indicate that the value of MPS should be inverted if

NLPS occurs.

Figure 13 represents theflowofdata intheprobability estimationprocessforone reso

lution layerorbitplane. Priortoencodingan

image,

eachcontext,foreachlayerandbit

plane, is initialized so that themost probable symbol is

0,

buttheprobabilities forthe

two possible symbols arenearlyequal. Whena pixelis encoded, thevalueofthepixel

Pixel

Compare

^ r

M An

PS

^

Valueof

MPS^

MPS Pixel

Arithmetic

Encoder

rayj

i L

bits

Context SWTCH

r

>

State Table

out

Next State (NMPSorNLPS) Renorm

i ' LSZ

(

s

7

1

Current State__

^Ar]ray

J

Figure 13

Structure

of

probability

estimation
(40)

and

it's

context word

(10

or 12

bits)

are usedto

determine

theprobability intervalto

be

encoded

by

an arithmetic encoder. Thecontextisused as anindex

into

arraysthat

hold

the current state and most probable symbolforthatcontext. The state

is

used as an

in

dex into

thestatetable tofindthe leastprobable subinterval

(LSZ),

andthepixel value

is

comparedwiththeMPS. Thesevalues are passedtoan arithmetic encoderthatgener

ates an output streamofbits. Whenever a renormalization occurs in the arithmeticen

coder, the probability state for that context is updated. The value ofthe current state

indexes thestatetable tolook up eitherNMPS orNLPS

depending

on whetheranMPS

was encoded or not. When the next state is

NLPS,

the value of SWTCH is also ac

cessed. If SWTCH is 1 then the valueoftheMPS array forthe current context

is

in

verted. Thisprocessisrepeated foreach pixelinthe image. Inthiswaythe algorithm

learnsthecorrect probabilitiesforeachpossible context.

2.6

Adaptive

Templates

The JBIG standard allows for a small amount of adaptivity in the contexts used for

probability estimation. This

feature is

knownas adaptivetemplates(AT). The primary

motivation forthisfeature istoimprovetheabilityofthealgorithmtoencodehalftoned

images. Halftonedimagesare the resultofusinga

binary

printingprocess torepresent

gray scale images.

They

occur often in compression applications as a result of either

scanning apreviously halftoned image or from capturing a continuous tone image and

thresholding

itwith a periodicpatternto simulate gray levels [20]. The important fea

ture ofhalftoned images is that

they

usually involve aperiodic pattern. In terms of a

Markovcontext for compressinganimage it meansthatthepixelsmostcorrelatedwith

thecurrent pixel canbeseveralpixels away.

In each ofthecontexts used forprobabilityestimation shown in figures 1 1 and

12,

one
(41)

only.

The

standard allows an encodertomovethispixel to anotherlocation

if

the en

coderbelievesthat

doing

sowill improvethe compression. It shouldbenoted thatthis

feature

shouldbeused withcare,

because

eachtimetheATpixelismoved,theprobabil

ity

estimation arrays are resettotheirinitialvalues.

They

mustreleamtheprobabilities

forthenewcontexts.

When anATmovementis specified,it onlyapplies to thecurrent resolutionlayer (and

bit plane).

According

to the standard, the ATpixel can be moved to any previously

transmittedpixel position within 127pixels inthehorizontal

direction,

and 255 lines

vertically.

However,

inpractice, it is suggestedthatencoders limitthe ATpixelmove

menttothecurrentline andthepreviouseight pixels.

An algorithmto determine when and wherethe ATpixel should move is suggested in

thestandard,althoughanyalgorithm canbeused. Itis also possibletouseno algorithm

at all.

2.7

Arithmetic

Coding

The heartoftheJBIGalgorithmisanarithmeticentropy coder. Itencodesthesymbols

andprobabilities thatweredescribed insection 2.5 forall oftheunpredictablepixels as

well as the pseudo-pixel generated

by

the typicalprediction algorithm. The output of

thearithmeticencoderisastream ofbitsthatmakeupthecompressedimagethatcanbe

stored or transmitted

depending

ontheapplication.

The algorithm used for arithmetic encoding is the same as the algorithm described in

section 1.4.

(42)

3

Optimizing

JBIG

Software

The

goals ofthe

JBIG

committee wereto

develop

an algorithmthatwould provide im

proved compression over a wide range of

documents

as previously discussed. This

could not be done without creating an algorithm that was significandy more complex

than thepreviousCCITTstandards,becausethesestandardswererelativelysimple algo

rithms.

However,

the new JBIG standard would not

be

effective if it could notbe im

plementedinanextremelyefficientmanner.

A considerable amount ofwork went into creating an algorithm that could be imple

mentedineither software orhardwareefficiently. Theresultisanelegant algorithmthat

uses a seriesoftables toperformcomplicatedfunctionssuch asresolutionreduction,de

terministic prediction, andprobability estimation. Since few calculations are required,

theresultingalgorithmshouldbeabletoprocesspixelsatrelatively highspeeds.

WhiletheJBIG algorithmiscapable ofhighspeeds,litdeornothing has beenwrittento

document software-specific techniques for

improving

theprocessing speedofthe algo

rithm. As a result, software developers who don't have experience with compression

algorithms could easily miss significant opportunities for

implementing

extremely fast

software.

Thepurposeofthischapteristodocumentseveraltechniques thathave beenusedinan

implementation ofthe JBIG algorithm to significantly improve execution time of the

software. Throughoutthisworkthe

following

assumptionshave beenmade:

All software is written in ANSI C. No assembly language is used because the re

(43)

All optimizations are algorithmic in nature. The goal, in general,

is

to reduce the

number of operations needed to perform atask.

While it is

possible to write soft

ware that takes advantage ofthe features of one specific platform, the final algo

rithm wouldonly

be

usefultoarelativelysmall audience.

All changes are compatible withtheexisting JBIG standard. Eventhough otherin

compatiblechanges mightbe

interesting,

they

would notbe extremelyuseful.

Memory

is

cheap. Thismeansthat it isvalidtousesignificandymorememorythan

might normally be required, if

doing

so will reduce the number ofrequired opera

tions. The limittothisstrategy isthat the techniquesdevelopedshouldbeusefulfor

applicationsthatrunin PCenvironmentswitha640K memory limitation.

Image datawill enterthe algorithm in aone pixel perbyte format. This should be

validforgeneralpurpose software sincesome applications will already have data in

this format. Applications with a packed

binary

formatwill haveto unpackthe im

age

data,

butthisisnot considered part ofthecompression algorithm.

3.1

An Efficient Algorithm for

Building

JBIG

Contexts

The largestobstacle to an efficient implementation ofJBIG is theneedto gathermany

pixelstogethertobuild largecontexts foreachpart ofJBIG. From

looking

atfigures

8,

9, 10, 11,

and

12,

it canbe seen thatthere are many differentcontextpatternsthatmay

berequiredfor anypixel. In

fact,

for anyspecificpixel, it may berequiredtobuildcon

texts forresolution reduction, typicalprediction,deterministic prediction, and probabil

ity

estimation, each ofwhich requires the use ofdifferent neighboring pixels. This is

especiallytrue when encoding differential

layers,

althoughthe techniques discussed in

this sectionarealsousefulwhenencodingthelowestresolutionlayer.

(44)

It

is important

torealizethateventhough each algorithm uses a

different

neighborhood,

therearemanypixelsthatarecommontoseveral neighborhoods. In

fact,

the totalnum

berof pixels neededto build all possible contexts

is

fairly

small. This can be seen

by

forming

the union of all possible context bits. When

doing

this the adaptive pixel

should be ignored because it must be handled separately, and the two line base layer

templateshouldbeignoredaswillbeexplainedlater. It

is

easytoseethat theresulting

union

is

threepixelshigh for boththelowresolutiondataandthehighresolutiondata.

3.1.1

Building

Columns

of

Three Pixels

To facilitate

building

a contextword, it is useful to group the pixels into columns of

three pixels. Figure 14 shows how the three pixel values are arranged within a byte.

Partofthereasonfor

doing

thisis because itcanbe done very quickly andeasily. The

mainreason,

however,

is thatonceit is donethesecolumns can

be

veryuseful in build

ing

context wordsforboththehighandlowresolutionpixelsas showninthenext sec

tion. Thecodefragment in figure 15 shows anexample ofhowthiscanbe done. Inthis

example,it isassumedthatpixel_data is originallyatwodimensional arrayofpixel

values stored as one pixel perbyte

holding

allthepixeldata forone stripeofone

resolu-Bits

3-7

Bit 2

Bitl

BitO

0

Unused

(0)

Pixel

from

the current

line

-

2

Pixel

from

thecurrent

line

-

1

Pixel

from

thecurrent

line

Figure 14

Pixels

stored as a column ofthree
(45)

unsigned char pixels

[STRIPE_HEIGHT]

[LINE_WIDTH]

; int

line;

register int

i;

register

long

*current_line;

register

long

*previous_line;

previous_line =

(long)

(lastline ofthepreviousstripe)

for

(

line = 0

; line < STRIPE_HEIGHT ; line++

)

{

current_line =

(long

*)pixels[

line

];

for

(

i = (layer_width

-l)/4 ; i >= 0 / i

)

current_line[i] |= (previous_line

[i]

1)

&

0x06060606;

previous_line =

current_line;

}

Figure

15

Code

fragment for

columnizing

pixels

tionlayer. Afterthe

loop

is

completed, eachbyteof thepixels array willholdthree

pixelsintheformatshownin figure 14.

Initially,

previous_line points the the last line ofthe previous stripe which is al

ready in the threepixel format (at the

References

Related documents