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
Table
of
Contents
Abstract
ix
1
Introduction
ofCompression Concepts
1
1.1
Compression
ofBinary
Images
2
1.2
Basic Information
Theory
3
1.3
Elias
Coding
8
1.4
Arithmetic
Coding
12
2
Description
oftheJBIG Image Compression
Standard
1 6
2.1
Purpose
ofJBIG
16
2.2
Sequential
vs.Progressive
Processing
18
2.3
ResolutionReduction
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
ArithmeticCoding
31
3
Optimizing
JBIG
Software
32
3.
1
An Efficient Algorithm for
Building
JBIG
Contexts
33
3.1.1
Building
ColumnsofThreePixels 343.1.2
Building
Common Context Words 363.1.3
Using
TablestoBuild Reordered JBIG Contexts39
3.2
Encoding
Both Differential Layer Lines in
One Pass
40
3.3
Moving Efficiently
throughSolid
Areas
42
3.3.2
DifferentialLayer Typical Prediction inSolid Areas
45
3.3.3
ArithmeticCoding
in Solid Areas(Sequential
ModeOnly)
48
3.4
Fast Deterministic Prediction
51
3.5
Removing
the
SWTCH
from the
Probability
Estimation
52
4
Results
56
4.1
Implementation
ofSoftware
56
4.2
Performance
oftheJBIG Algorithm
58
4.3
Comparison
ofJBIG
andCCITT
Group
3
61
4.4
Effect
ofImage Noise
onCompression Times
63
4.5
Halftone Images
67
5
Conclusions
70
Appendices
Appendix A
BlockDiagrams
oftheJBIG
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
ofResolution Reduction
forProgressive
Transmission90
C.3
Examples
ofImages
withRandom Noise
96
C.4
Examples
ofNoisy
Images
afterFiltering
103
List
of
Figures
Figure
1
Formation
of adigital
Image
2
Figure 2
General
Information Source
4
Figure
3
Example
Pixel
context(or neighborhood)
for
a4th
orderMarkov
Source
7
Figure 4
Example
of recursiveprobability interval
subdivisionin Elias
coding.9
Figure
5
Alignment
ofthe
arithmeticcoding
registers13
Figure 6
Four
phases ofhigh
resolution pixels1 9
Figure 7
Resolution Reduction
of animage
20
Figure
8
Context
for Resolution Reduction
21
Figure
9
Context
for
differential layer
typical prediction22
Figure 1 0
Context for Deterministic
Prediction25
Figure 1 1
Encoding
contexts for thelowest
resolutionlayer
27
Figure 12
Encoding
contextsfor differentiallayers
28
Figure 13
Structure
ofprobability
estimation29
Figure 14
Pixels
stored as a column ofthree pixels perbyte
34
Figure
15
Code fragment for
columnizing
pixels35
Figure 16
Code
fragment forbuilding
common context words36
Figure 17
Pixel
orderfor
common context words37
Figure
18
Examplecodefragments for
combining
high
andlow
resolutioncontext words
39
Figure
19
Bit
orderofprobability
estimation contextfor differential layer
encoding (Phase
3)
39
Figure
20
Software
examplefor
processing
twolines in
one pass41
Figure 21
Efficient resolution reductionin
solid areas44
Figure 22
Efficient
typical predictionin
solid areas47
Figure
24
Efficient deterministic
prediction52
Figure 25
Improved
structureofprobability
estimation54
Figure 26
Module Diagram for
theJBIG Compressor
56
Figure 27
The
effect ofimage
noise onJBIG
compression speedfor
progressive and sequentialtransmission
65
List
of
Tables
Table
1
Number
ofdeterministically
predictable statesin the default DP
tables25
Table
2
JBIG
executiontimeson aVAXstation
4000/60,
in
seconds58
Table 3
JBIG
executiontimeson aSun Sparc
2,
in
seconds59
Table 4
JBIG
execution timeson aSun
Sparc
1
0,
in
seconds59
Table 5
JBIG
execution timeson anAmiga
3000,
25MHz
68030,
in
seconds ...,
60
Table 6
JBIG
compression ratiosfor
testimages
61
Table 7
Comparison
of compression ratiosfor
binary
image
compressalgorithms
62
Table 8
Comparison
of execution timesfor
binary
image
compressionalgorithms on a
Sun
Sparc
2
63
Table 9
Effect
ofimage
noise onJBIG
compressionfor
theCCITT image
set.. 64Table 1 0
Effect
ofremoving
image
noise onJBIG
compression(CCITT Test
Set)
66
Table
1 1
JBIG halftone
execution times on aSun
Sparc
2,
in
seconds67
Table 12
JBIG halftone
compression ratios 67Table
13
Comparison
ofhalftone
compression ratiosfor
binary
image
compression algorithms
69
Table 14
Comparisonofhalftone
compression execution timesfor
binary
Abstract
JBIG
is
a newbinary
image
compression standard thatis designed
tohandleboth
textandhalftoned documents. It
significantly
outperformstheCCITT
Group
3
andGroup
4 standardsespecially onhalftoned
documents.The JBIG
standard is based on an arithmetic encoder, and it
features
adaptive probability estimation, adaptive templates, andthree 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 JBIGalgorithmisdescribed,
and severaltechniquesaredevelopedtoefficiently im plementthe algorithmin software. Themost importanttechniques include an efficientscheme for
building
the context that are required, andtaking
advantage of large all-white or all-black regions ofimages
by designing
very efficient loops for processingthose areas. Other techniques are also
discussed,
such as, efficient implementation of deterministicprediction,andanimprovedmethodforhandling
theconditional exchange condition.Timing
information is given for the final implementation on several platforms. The JBIG algorithm is compared with the CCITT
Group
3 andGroup
4 algo1
Introduction
of
Compression Concepts
Within digital computer equipment,
information is
represented as a series of symbolsthat are encoded as
binary
numbers.Almost
any information can be represented thisway
including
characterbased
datasuch as reports and computerprograms,databases
of numbers representing scientificinformation
or accountinginformation,
and digital images. Informationof this type can be stored in several ways, but the storage space is
often costly. Inaddition,theinformationcanbetransmittedfromone placeto another,
butwhenlargeamounts ofdataare
transferred,
itcantakealong
time.Toovercometheproblemsofstorage andtransmission
time,
itisoften usefulto convertthe 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 arenecessary 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 ofinformation
theory
will be introduced. Thiswillbefollowedby
adiscussionof animpractical but instructionalencodingtechniqueknown as Elias coding [2].
Lastly,
arithmeticcodingwill be introduced. Arithmetic coding is analgorithmthatsolvesthe shortcom
ings
ofEliascoding, anditistheheartoftheJBIGstandard.1.1
Compression
ofBinary
Images
Ina greatmanyapplications
it
isusefultousenumbersina computertorepresenta picture orimage. This canbe
done
a number ofdifferent
ways. In general, an originalscene ordocument
is
sampled atdiscrete locations
by
ananalogsensorthatiscapable ofsensing the brightness of the image within a sample as
illustrated
in figure 1. Eachsample,or pixel(short forpictureelement)
is
thenconvertedtoa numberthatrepresentsthe
brightness
ofthe image within the sample. The number ofbits used to representeach 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 :^JiHH**?*:::*::: ::
%\
ts
8Hli
:|::S JK5J MW$' ;*^
/
/
Original Image
Sampled
Image
saHSaBWaSBBaa
Sensor
Electronics
Assigna numberbased
on averagebrightnessof
-*. thesample.
Generally
between0
and255.applications,where
images
are generally comprised ofblack and white text documentseach pixel
is
storedas a 1-bitnumber. These 1-bitimages
areknownasbinary
images.Anexample oftheuseof
binary
images
inabusiness
applicationis
afacsimilemachine.Atypical FAX machine scans an
8.5
x 11 inch sheet of paper and generates a 1728 x1
100
pixelimage. The resultingimage
contains 1,900,800pixels. SincemostFAXmachines transmit data through a phone line at
9600
bits/second,
it would take about 3minutes and20 secondsto transmit the entireimage. Formost
documents,
however,
itis
possibleto compressthe image to 1/1 0th ofits
originalsize orless. Thisis
accomplished through the use of standard FAX compression algorithms.
As
a result, mostdocumentscanbetransmittedin 20secondsorless.
Another application in which
binary
images are common is inbinary
printers such aslaserprinters. Sincemostlaserprintersprint300 dotsperinchormore, afullpageim
age requires 8,415,000pixels. Inotherwords, a standard
high-density
PCfloppy
couldonly holdonefullpage
image,
Ifthe images arecompressed,however,
it ispossibletostoreasmanyas 10-20 full-page imagesona single
floppy
disk.1
.2Basic 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 foundationforthistheory
was developedby
Shannon
[3]
in 1948. Foramore complete introductiontoinformationtheory
as itrelates to image compression see Rabbani and Jones [4]. For a thorough discussion of
backgroundand uses ofinformation
theory
see refs. [5-6].A
binary
image is
one example of asource ofinformation.
When itis
sentto alaserprinter, each
binary
pixel representsinformation
for the printer. The pixel tells theprinterwhethertoprint 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 todefine
aninformation
source,5,
that generates a series ofsymbols asshown in figure 2. Eachsymbol emitted
by
S ispartofafixedfinite alpha betof sizen,soS={si, ^ >s
}
, andtheprobabilityofanysymbol,s-,inthe alphabet is aknown fixedvaluepis,). Ifeach symbol released
by
the source is statisticallyindependent of allother symbols released
by
S,
thenS is knownas a DiscreteMemo-rylessSource
(DMS)
[4].Tounderstandtheinformationcarried
by
thesesymbols,considerapersonreceivingthesymbols 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. Thelow probability symbol represents an event that was not expected, so it carries much
more information. Ingeneral,it istrue thattheamount ofinformationcarried
by
a sym bolis
inversely
relatedtotheprobability ofthe symbol. Iftheinformationcarriedby
aSource S
+s?c
*b'
symbol
^
is
encodedby
abinary
alphabetforusein adigital system,it
is givenby
theequation
I(s.)
=-log2p(5f)(1)
Since
theDMS
generates symbols with aknown
probability, the averageinformation
per symbol canbecalculated
by
summingtheinformationgeneratedby
eachsymbolinthe alphabet weighted
by
theprobability ofthe symboloccurring as givenby
the equation
H(S)
=jy(Si)I(Si)
=-Yj>(Si)log p(st)
(
2)
The quantity
H(S)
is knownastheentropyof sourceS. Itrepresentstheaverage amountofinformationthat the source,
5,
can generate. Itis auseful quantity because it repre sentsthe averagetheoreticallimitof algorithms thatencode thesymbolsusing abinary
alphabet.
According
toShannon's noiseless sourcecoding theorem,nouniquelydecod-ablecode canhaveanaveragelength lessthatH(S).
As an example, consider aDMS generating bits for a
binary
image,
S =[ 0,
1}
.Any
two symbols generatedby
the source are statisticallyindependent,
andtheprobabilities ofthe twooutput symbols arefixed. Ifthe twosymbols areequallyprobable,i.e.p(0) =p(l)=
0.5,
thenby
usingequation
2,
theentropyofthesourceis
calculatedtobe1.0
bit per pixel. Thismeans thattrying
to compressanimage generatedby
thesource wouldbe fruitless becausetheentropy ofthesourceis equalto thenumber ofbits inthe sym
bol sequence without compression. Iftheprobabilities ofthe twosymbols areunequal,
however,
the average amountofinformationper symbol wouldbe lower
and compression wouldbepossible. Considera
binary
DMSwherep(0) =0.95andp(l)= 0.05. In this case, according to equation
2,
theentropyofthe source is0.29
bitsper pixel. Thismeans that compressing an
image
generatedby
the source couldbe
a useful step because
it
shouldbepossibletocompresstheimagetoabout athirdofits
original size.While
this exampleis
usefulforillustrating
theconcept ofentropy, itis
limitedbecause
typical informationsources are not statistically
independent.
Imagine a personreadingEnglishtext one character atatime. If he sees thestring
'exampl',
he caneasily guesswith ahigh degreeofaccuracythat thenext character
is
an 'e'. Inthiscase, the Vcarries
very little informationbecause
thereaderknowsthat theprobabilityof anV is
unusually 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
conditionallydependenton m previous symbols.The probabilityof asymbol,s-is denotedas
p( sAS) where i=
1,
2,
...,n and
S
isavectorof mprevioussymbolsSinceeach ofthem previous symbolsinthe
S
vectorhasn possiblevalues, anm orderMarkov sourcehas
nm
possible states. Withineach state, theMarkov sourceis similar
to a DMS inthateach ofthen possible symbols hasafixedprobability.
Therefore,
theentropyofasingle state oftheMarkov source,
SM,
isgivenby
H(SM)
=-Yp(Si\S)log
p(Si\
S)
(
3)
i=lfor 1 <M<nm. TheoverallentropyoftheMarkovsourceisthesum oftheentropies of
eachstatetimes theprobabilitythat thestatecan occur
H(S)
=It
is important
tonotethat theentropyof a sourcethatismodeled as aMarkovsourceis
alwaysless thanorequal to the entropyof a sourcethat
is
modeled as a DMS. This isbecause
the Markov source takes advantage of the localinformation
to make an improved prediction ofthe emitted symbols. As a result, on average,the symbols carry
less
information.Whena
binary
image ismodeled as an m orderMarkovsource,theprobabilityofeachpixel
is
dependenton mpreviouslytransmittedpixels.Typically,
thepixels are selectedto
be
the m pixels closestto thepixel ofinterest. These nearbypixelsthat are usedto encode apixel are known as thepixel's context or thepixel's neighborhood. Figure 3showsatypicalcontextfor 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 algorithmgrows 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 usedby
the JBIG algorithm, without unusually large memoryrequirements.Secondly,
theimprovementsuppliedby
theMarkovmodelis dependent on
knowing
the conditionalprobabilities to more accurately predict eachpixel. It
is
not generally true,however,
that the conditional probabilities used in aPreviously
Transmitted
Pixels
Pixel
Context
Figure
3
Example Pixel
context(or
neighborhood)
for
a 4th orderMarkov
Source
Markov
model are thesamefor
allbinary
images.
Infact,
theconditional probabilitiescan change
dramatically
from
image
toimage.
To
overcome this problem, the JBIGstandard uses an adaptive
probability
estimate technique that allows the algorithm to"learn"
the conditional probabilities for each
image.
This mechanism for this will beexplainedinsection2.5.
To summarize,theinformation content of a set of symbols
has
been described intermsof entropy. It
has been
assertedthattheentropyof a source canbe
calculatedbasedon astatistical model of the generated symbols. It has also been
implied
that a sequence ofsymbols generated
by
aninformationsource canbeencodedusingabinary
alphabetintoa
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 outputbinary
data.Nothing
has beensaidabouthowthe symbols are encodedtogeneratethiscompressedoutputdatastream.
In
fact,
there are severalwellknown and simple algorithms for encoding symbols suchas Huffman coding
[7]
andrun-lengthcoding[8]
thatare oftenused. Thesealgorithmsusevariable length
binary
codestorepresentone ormore source symbols. While thesetechniques are simpletouse,
they
are notincluded intheJBIGstandard, andwillnotbediscussed here. Within
JBIG,
the estimated probabilities ofeach symbol are encodedusing 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 forre-quiredto encode a sequence of symbols
is
close to the entropy ofthe sequence.The
drawback
ofthe technique is that itis
notimplementable
forimage
compression because it requires theuseofextremely largeregisters.
Regardless
ofits
implementationlimitations,
it
is instructional to understand ofthebasic
concepts ofElias coding as abasis
for understandingarithmeticcodingwhichwillbe discussed
insection1.4.In Eliascoding, astringof symbols generated
by
asource,S,
isencoded as abinary
realnumberintherange of
[0, 1)
by
recursively subdividing probability intervals. Figure 4shows agraphicalrepresentationofthis typeofsubdivision. The entire initialregionis
divided
into
twointervals
proportionaltotheprobabilities of0
and1. Whenasymbolis
encoded,
its
subinterval is selected andproportionally subdividedforthe nextsymbol.Thiscontinuesuntiltheentirestring isencoded.
Tobemoreprecise,consider aseries of
binary
symbolstobeencoded inwhich0 isthemost 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 0Figure
4Example
of recursiveprobability
interval subdivision
in Elias
coding.ofthese symbols, the real numberrange
[0, 1)
is
subdividedinto
twointervals, [0,
p)representing the symbol
0,
andfp, 1)
representing the symbol 1. If the symbol0 is
coded,then theinterval
[0,
p)is
subdivided againinto
regionsthatare proportionaltop2 1
andq,namely
[0,
p
)
for0,
and[p
,p) for 1. Ifinstead
oftransmitting
thefirst symbolas a
0,
thefirst
symbolhad beena1,
then thenewintervalwouldhave
been[p,
1),
anditwould have been subdivided into regions proportionaltop and q,
[p,
p+qp) for0,
and[p+qp,
1)
for 1. Thisprocedure ofrecursivelydividing
a subinterval intotwonewsub-intervalsthatareproportionalto theprobabilities ofthesymbols
being
transmittedis
repeated 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 subdividedinto one offourpossible intervals. In general, after
transmitting
n symbols the initial 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 besubdividedin 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 (thedistance to the firstpoint in the next interval). The width ofthis final
interval,
w, isgiven
by
theequationv =
f[p(Si)
(
5)
th Wherep(s-
)
is
theprobability of the i symbol in the string. The reasonthat this
is
important is
thatwis
exacdyequalto thejoint
probabilitythatthe entirestringwill occur. Basedon the discussion in section
1.2,
it
shouldbe
clear that the entropy oftheentirestringgenerated
by
source5 is/5=-log2w
(6)
Once the final subinterval is selected, it can be uniquely identified
by
encoding anypoint withinthesubinterval as a
binary
fraction. Thisis
doneby
creatingabinary
num--1 -2
ber,
b-ibj-.- that is interpretedasferx2 +bj^2 + .... A decoderthatreceives thisfaction can
identify
the subinterval that contains this point, and therefore, completelydecodetheentirestring.
To determinethe bestchoice ofpointstoencode,thevalue ofthe
beginning
oftheintervalisencodedandthe first
|7e 1
bitsofthebinary
fractionareused,where11
representsthe ceiling function. The resulting fractionrepresents the shortest possible
binary
codeto transmit theinformationofthestringandmustbewithinthefinalsubintervalbecause
w^lM
(7)
So
far inthis discussionofEliascoding,it has beenassumedthat theprobabilitiesp andqare fixedandglobally known
by
boththeencoderanddecoder. Asseenintheexampleof aMarkov source in section 1.2,
however,
theentropyofa set ofdatacanbe lowered
by
using alocal contexttomake betterpredictions of eachnewsymbol. Ifthe information 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 currentMarkov state. This added complication does not change anything inthe previous dis
cussion. In general, as
long
as the probabilities used for each symbol are causallyknown
by
boththeencoderanddecoder,
theElias
codingalgorithmcouldoptimallyencode anduniquely
decode
anystring.The majordrawback of theElias algorithmisthat encodinga stringofarbitrary length
requires
infinite
precision registers. When encoding abinary
image consisting of millions ofpixels,registers that are severalmillionbits
long
couldberequiredto storethelocationofthe
beginning
oftheintervalandthecurrentwidthoftheinterval. Thisproblem and others related to it are overcome
by
a compression technique known asarithmetic coding.
1.4
Arithmetic
Coding
Arithmetic coding
[9-13]
is arelatively newencodingtechnique that isthecentral coding
algorithmfortheJBIGcompression standard. While it is similarinconcept toEliascoding, it overcomesthe infiniteprecision problems. This is accomplished
by
using arescalingprocedurethat 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 onetokeep
trackofthe bottomof the subinterval
(
C
). Theseregisters define the current subinterval exA
register)falls
belowonehalf,
bothregisters aredoubled
repeatedlyuntiltheAregisteris
abovethe onehalflevel. This scalingprocessis knownasrenormalizationandit effectively
slidesbothregistersdownthearithmetic axis ofthetwoEliasvalues as shownin
figure 5 untilthe first 1 bit inthefractionalrepresentation oftheElias intervalis
thehighorderbit inthe arithmeticAregister. The bits shifted out oftheC register arethe
bits
that aretransmittedas part oftheencodeddatastreamwithoneexception whichisknownasthecarrypropagation problem.
The carry propagation problem iscaused
by
the factthat the value ofthebeginning
oftheElias subinterval will alwaysstaythesameorincrease. When it
increases,
thevalueofthe arithmeticCregister can overflow. Theresult ofthe
binary
overflow willbethatall 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 anoverflowoccurs,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 XXXFigure
5
Alignment ofthe arithmeticcoding
registersAnother important
concept tounderstand aboutthe arithmetic coderis
the factthatit is
computationallyefficient. When encodinga
binary
symbol, themostprobable symbolwill be encoded ahighpercentage ofthe time. Whenthis occurs, theA registerisre
duced
by
the size oftheleast
probable subinterval. The exactsize oftheleastprobablesubinterval
is
theproduct ofthe currentinterval size,A,
andtheprobability oftheleastprobable symbol,q.
Since
themultiplyis
undesirable,it is
avoidedby
replacing Awiththe statistical average of
A,
whichis
a constant.By
usingthe statistical average ofA,
the
following
approximationismadetocalculatean estimate oftheleastprobableinterval,for everypossible valueofq
qXA~qXa =
qe
(8)
whereais theaverage overtheprobability
density
ofA,
andqg
istheresultingestimateof the least probable subinterval size. Sincethe normalizedvalue ofA is bounded be
tween0.5 and
1,
thevalue ofAcanbereplacedby
awithoutintroducing
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 asfollowsC+-C+A-qe
A-qe
Eventhoughtheapproximationoftheq intervalcansimplifythearithmeticcalculations
without
imposing
alarge codinginefficiency,
itdoescauseone anomaly.Since
theestimationofthe q intervalis independentofthecurrent interval size,whenthe
interval, A,
larger
than the most probable subinterval.This
can cause afairly
large
inefficiency.Since
this condition canbe causally detectedby
adecoder,
itcanbe correctedby
boththe encoder and decoder
by
using the least probable subinterval to encode the mostprobable symbol andusing the most probable subintervalto encode the leastprobable
symbol. This strategy
is
knownas conditional exchange andit is
usedin
theJBIGarithmetic encoder.
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 ofthecomponents ofthealgorithmwillbe discussedsothat thereader
has
anunderstandingoftheissues and complexities relatedto the algorithm. Withthis understanding, thereader
should be aware ofthe need to
develop
efficient techniques forimplementing
the fullalgorithm.
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
ofJBIG
WorkonJBIG (Joint Bi-level Image Experts
Group)
began in 1988. Itspurpose wastodefine astandard,CCITT T.82andISO
11544,
for compressingbinary
image data forawide 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,
theprimarybinary
image compression standards in the world were theCCITT
Group
3
[17]
andGroup
4[18]
standards. These standards are reviewed andone
dimensionally
encoderuns of consecutive white and blackpixels oneveryk lineofthe
image.
Betweentheonedimensionally
encodedlines,
thelines
are processedby
encoding differences between twoconsecutive
lines
using atechniqueknown asModified
READ (Relative ElementAddress
Designate).Since
the Huffman codes usedby
these standards were designed specifically for textbusiness
documents,
the algorithmsperform wellonthat typeofdocument. Halftoned
images, however,
havedistinctly
differentcharacteristics fromtextdocuments. Asaresult, halftoned images are not com
pressedwell
by
CCITTGroup
3
andGroup
4. Infact,
the result ofusingGroup
3 orGroup
4 on ahalftoned image is normallya larger filethan the original, becausethesealgorithms cannot adaptto thelocalstatistics ofahalftoned image.
They
often expandthedocumentinsteadofcompressing it.
JBIGwas developedtobeasignificant improvementover
Group
3 andGroup
4. Specifically, it was desired that the JBIG algorithm provide the
following
improvementsovertheprevious standards:
1. provideimprovedcompressionfortextandlineartdocuments (seesection
4.3),
2. providesignificant compressionofhalftoneddocuments (seesection
4.3),
and3. providethe abilityto transmitimagesprogressivelyaswellas sequentially (see sec
tion2.2).
To accomplish these goals, it was necessary to
develop
an algorithm thatwas significantly more complex than
Group
3
orGroup
4. This extra complexity ispossible because of advancesin integratedcircuit
technology
andmicroprocessorperformance.2.2
Sequential
vs.Progressive
Processing
In many
image
processingapplications,animage is
processed atfullresolutionfrom leftto right and from
top
to bottom in a single pass.This
type ofprocessingis
knownassequential processing. CCiTT
Group
3
andGroup
4 are examples of sequential compression 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 asignificant 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 resolutionversions 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 intheimage,
the user can wait for the fullimagetobetransmitted. Ontheother
hand,
iftheuseris
notinterested intheimage,
it would be possible to terminate thetransmissionwithout waiting. This
feature is
very important in image
browsing
applications where a useris
searching though along
listof availableimages.2.
Supporting
peripherals withdiffering
resolutions: Images can be compressedandstored in animage database and still used on avariety of peripherals at several
different resolutions. For
instance,
animage couldbe extractedfromadatabase
forver-sion ofthe
image. The
sameimage
couldbe
printed at appropriate resolutions on a300
DPIprinterora600 DPIprinter.The disadvantage
of progressivealgorithmsis
thatthey
require a pagebuffertostoretheentireimage. This addsto thecost andcomplexityofthesystem.
Thealgorithm
defined
by
theJBIG standard can operate both sequentiallyand progressively. In addition, JBIGprovides a mode
known
as progressive-compatible sequentialmode. In this mode, an
image
isdivided
into horizontal sections called stripes. Thestripe is
decomposed
into therequired resolutionlayers and compressed as inprogressivemode. 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 andtransmittedinprogressive 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 oftheresolutionlayersmustbecompressed.
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 ofhigh
resolution pixelsThe
circle represents alowresolution pixel andthefour squares representthefourhighresolution 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 resolutionimage,
ahighresolutionimage isprocessed
by
an algorithmthat creates anewimagethat is halftheheight andhalfthewidth ofthe high resolution image. This process is repeated for each new resolution
that isneeded. Figure 7 illustratesthisprocess fortworeductions. Eachoftheseimages
is
thencompressed. A decompressor beginsby
decoding
thelowresolutionimage andbuilds upto thedesired highresolutionimage.
The JBIG specification defines a default resolution reduction algorithm, although it is
possibletouse acustom algorithmtodothereduction..
Half
Resolution
Quarter
Resolution
Full
Resolution
The defaultresolution reduction algorithm uses atable to generate new low resolution
pixels so that theimplementation
is
efficient. Itis based
on a filterthatis
designedtopreservethe average
density
ofanyarea.Some
exceptionsto the filter designare madeto the table to improve thequality ofthe
resulting
low resolution images. The exceptionsaremadeto
improve
theabilityofthe algorithmtopreservesedges,lines,
periodicpatterns 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 Reduction2.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 thesepredictionalgorithmscanbeenabledordisabled
depending
onthedesired complexityofanimplementation.Two oftheseprediction algorithms,one forthelowest resolution
layer,
and one for allother
layers,
are known as typical predictors.They
are called"typical"
because
they
predict eventsthatare
typically
true, butnotalwaystrue. Atthebeginning
of eachline,
apseudo-pixelisencodedto tell thedecoderwhether or nottheconditionistrue forthe
entireline. Ifthe conditionis
true,
then the algorithmcan predictpixels; otherwise,thealgorithm
is inactive
forthatline.The
third prediction algorithm is known asdeterministic
prediction. This algorithmuses aknowledgeof the resolution reductionto
determine
whenonlyone valueis
possible forapixel.
2.4.1
Differential
Layer Typical Prediction
Thepurpose ofdifferential layertypicalprediction
(DTP)
is
to predict solid areas of animage. 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. Whilethisisnot 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
at the
beginning
ofthefirst line
to tell thedecoder
whether or not the assumptionis
valid.
Whena pair ofimage
lines
is foundto betypical,
itmeansthat this is a solidarea, andall ofthepixels can
be
skipped. The decoderwillknow howtogeneratethepixelsjustby
readingthevalue ofthepseudo-pixel. Sincemostdocumentscontain alarge amountof solid area
(especially
whitebackground),
many ofthepixels inthedocument canbeskipped. 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 reducesthecompression 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,
foreachpairoflines anewpseudopixelis encoded. Theprobabilities associated withthis
pseudo-pixelare muchlessbiasedthan theskippedpixels, andtherefore, carrymore in
formation. Asaresult,the totalentropyofthedocumentdoesnot change significantiy.
2.4.2
Lowest Resolution Typical PredictionThe algorithm usedfortypicalprediction inthe differentiallayer assumesthepresence
ofalowerresolution image. Whenthe lowestresolution layer
is
encoded (orthe onlyresolutionlayerforsequentialprocessing), aseparate algorithmisneeded. Inthiscase,
JBIG defines alowest resolutionlayertypicalpredictionalgorithm (also knownas
base
layertypical prediction or
BTP)
that simplytests two consecutivelines
todetermine
ifthey are exactly the same. Ifthe lines are found tobe the same, a pseudo-pixel
is
encodedtotransmitthe
information,
andtheentirelineis
skipped with nofurthering. Ifthe
lines
are notthe same,thenthe pseudo-pixelis
encodeddifferently,
andtherest ofthe
line is
processed normally.Typicalprediction
is
most useful forprocessing
blanklines
within the image. Forthisreason ahighpercentage ofthepixelsinmost simple
business
documents donot needtobe
processed. As with differential layer typical prediction, this greatly improves thespeedof asoftware
implementation,
but is haslittle
effectonthe compressionratiosofthealgorithm.
2.4.3
Deterministic Prediction
Thepurpose of
deterministic
prediction(DP)
istoremove thenecessityofencodingredundant 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
ashaving
onlyonepossible 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. Ifanyoftheother pixels were
black,
then thelowresolution pixel wouldhave been black.Whilethisexampleassumesaverysimpleresolutionreductionalgorithm,thebasiccon
ceptcanbeappliedfor anyreduction algorithm. In
fact,
forthedefaultresolution reduction algorithm, most images contain a significant number ofpixels that are predictable
by
thedeterministicprediction algorithm.The deterministicprediction algorithmistabledrivensothatitcanbe
implemented
efficiently. Separate tables areused for eachofthe four high resolution pixels associated
Figure
10
Context
for
Deterministic
Prediction
thatwere used
by
theresolution algorithm. Infigure10,
thepixelsthatareusedtobuildthe
index
are shown alongwiththeorderinwhichthebitsare placedinthe index. Thepixels numbered
8, 9, 11,
and12arethepixelsbeing
predicted. Foreachpixel,onlythepreviouslytransmittedpixels areused.
Specifically,
forpixel8,
theindex isconstructedfrompixels
0-7,
forpixel9,
the index is constructed from pixels0-8,
forpixel11,
theindex is constructed from pixels
0-10,
and forpixel12,
the index is constructed frompixels 0-11. The JBIGstandarddefinesthefour deterministicpredictiontables thatwill
work withthedefault resolution reductionalgorithm. Inthese
tables,
alargenumber oftheentriesareforpredictable pixels. Table1
defines
thenumberof context states possible foreachpixelandhow manyofthesestates represent predictablepixels.
Target
Pixel
Number
ofContext
States
Number
ofStates
withPredictable Pixels
8 256 20
9 512 108
11 2048 526
12 4096 1044
Table
1 Numberofdeterministically
predictable statesin
thedefault
DP tablesIt
is
also possibleto transmit a set of custom DPtables as a part of the image headerdefined
by
the standard. This is required ifa non-standard resolution reduction algorithm is
used.The
main purpose ofdeterministic
predictionis
toimprove
the compressionperformance ofthe algorithm. Even though DPpredicts only avery few pixelsrelative to the
large
number predictedby
typicalprediction, ithas
a muchlargereffect on theoverallcompressionratio. To understandwhythisisthecase, considerthepixels that are pre
dicted
by
thedeterministicpredictionalgorithm.Many
ofthepixelspredictedby
DPdonothave
highly
skewedprobabilities. Inotherwords,the pixels predictedby
DP carrymore 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
2.5
Probability
Estimation
Within the
JBIG
standard probabilities are conditionallyestimatedbased on agroup ofpixels in the neighborhood ofthe current pixel.
This is
similarto the Markov model discussed insection 1.2. One ofthe problemswith aMarkov modelis
that the condi tionalprobabilitiesthatare usedarenotconsistentfrom imageto image. To overcome thisproblem,theJBIG standarddefines
a method ofadaptiveprobabilityestimation so thatitcanlearnthecorrectprobabilities asitprocessesanimageWithin
JBIG,
a neighborhood of 10pixels is defined around the pixelbeing
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
11
Encoding
contextsfor the lowest
resolutionlayer.
When
encoding
thebaselayer,
therearetwopossibleencodingcontexts, atwolinecontext,
and athreeline context. The JBIG standard suggeststhatthetwolinecontextwillallow softwareto runsomewhatfasterwhilethe three linecontext will improvetheen
coding
by
about5%.When encoding the differential resolution
layers,
there arefour different contexts thatareused. Thechoice of context
is
dependentontheposition(orphase)ofthehighreso lutionpixelbeing
encodedrelativetoits corresponding lowresolution pixel. ThevaluesX
J
IX
J
\x
)
[
X
Phase
2
Phase
3
ofthe 10pixelsintheneighborhood arecombinedwiththetwobitvalue ofthephaseof
thepixeltoforma 12bitcontext. Withineach resolutionlayer (andalsowithineachbit
planeformultibit
images),
the algorithmkeeps trackofthecurrentmostprobable symbol
(MPS)
andthecurrentprobabilitystate(ST)
for everycontext.The
standarddefines
aprobabilityestimation statetablewith
113
possible states. Foreachstate inthetable,
an estimationoftheleast probable symbol subintervalwidth
(LSZ)
isstored. LSZ is a16 bitrepresentation ofthevalueq defined inequation
8
on page 14. Alsoincluded inthe state tableisthe nextprobability estimation stateto beused fora contextwhenthe
encoded valueisthemost probablesymbol
(NMPS),
andthestate tousenext whentheleast probable symbol is encoded (NLPS). The probability estimation state changes
eachtime a renormalization
is
performed. The last value in the state table also is thevalue, 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,foreachlayerandbitplane, is initialized so that themost probable symbol is
0,
buttheprobabilities forthetwo possible symbols arenearlyequal. Whena pixelis encoded, thevalueofthepixel
Pixel
Compare
^ r
M An
PS
^
ValueofMPS^
MPS PixelArithmetic
Encoder
rayj
i L
bits
Context SWTCH
r
>
State Table
out
Next State (NMPSorNLPS) Renorm
i ' LSZ
(
s
71
Current State__^Ar]ray
J
Figure 13
Structure
ofprobability
estimationand
it's
context word(10
or 12bits)
are usedtodetermine
theprobability intervaltobe
encoded
by
an arithmetic encoder. Thecontextisused as anindexinto
arraysthathold
the current state and most probable symbolforthatcontext. The state
is
used as anin
dex into
thestatetable tofindthe leastprobable subinterval(LSZ),
andthepixel valueis
comparedwiththeMPS. Thesevalues are passedtoan arithmetic encoderthatgenerates 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 whetheranMPSwas encoded or not. When the next state is
NLPS,
the value of SWTCH is also accessed. If SWTCH is 1 then the valueoftheMPS array forthe current context
is
inverted. 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 primarymotivation forthisfeature istoimprovetheabilityofthealgorithmtoencodehalftoned
images. Halftonedimagesare the resultofusinga
binary
printingprocess torepresentgray scale images.
They
occur often in compression applications as a result of eitherscanning apreviously halftoned image or from capturing a continuous tone image and
thresholding
itwith a periodicpatternto simulate gray levels [20]. The important feature ofhalftoned images is that
they
usually involve aperiodic pattern. In terms of aMarkovcontext for compressinganimage it meansthatthepixelsmostcorrelatedwith
thecurrent pixel canbeseveralpixels away.
In each ofthecontexts used forprobabilityestimation shown in figures 1 1 and
12,
oneonly.
The
standard allows an encodertomovethispixel to anotherlocationif
the encoderbelievesthat
doing
sowill improvethe compression. It shouldbenoted thatthisfeature
shouldbeused withcare,because
eachtimetheATpixelismoved,theprobability
estimation arrays are resettotheirinitialvalues.They
mustreleamtheprobabilitiesforthenewcontexts.
When anATmovementis specified,it onlyapplies to thecurrent resolutionlayer (and
bit plane).
According
to the standard, the ATpixel can be moved to any previouslytransmittedpixel position within 127pixels inthehorizontal
direction,
and 255 linesvertically.
However,
inpractice, it is suggestedthatencoders limitthe ATpixelmovementtothecurrentline 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 ofthearithmeticencoderisastream ofbitsthatmakeupthecompressedimagethatcanbe
stored or transmitted
depending
ontheapplication.The algorithm used for arithmetic encoding is the same as the algorithm described in
section 1.4.
3
Optimizing
JBIG
Software
The
goals oftheJBIG
committee weretodevelop
an algorithmthatwould provide improved compression over a wide range of
documents
as previously discussed. Thiscould not be done without creating an algorithm that was significandy more complex
than thepreviousCCITTstandards,becausethesestandardswererelativelysimple algo
rithms.
However,
the new JBIG standard would notbe
effective if it could notbe implementedinanextremelyefficientmanner.
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 algorithm. As a result, software developers who don't have experience with compression
algorithms could easily miss significant opportunities for
implementing
extremely fastsoftware.
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
All optimizations are algorithmic in nature. The goal, in general,
is
to reduce thenumber of operations needed to perform atask.
While it is
possible to write software 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 isvalidtousesignificandymorememorythanmight normally be required, if
doing
so will reduce the number ofrequired operations. 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 image
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
atfigures8,
9, 10, 11,
and12,
it canbe seen thatthere are many differentcontextpatternsthatmayberequiredfor anypixel. In
fact,
for anyspecificpixel, it may berequiredtobuildcontexts forresolution reduction, typicalprediction,deterministic prediction, and probabil
ity
estimation, each ofwhich requires the use ofdifferent neighboring pixels. This isespeciallytrue when encoding differential
layers,
althoughthe techniques discussed inthis sectionarealsousefulwhenencodingthelowestresolutionlayer.
It
is important
torealizethateventhough each algorithm uses adifferent
neighborhood,therearemanypixelsthatarecommontoseveral neighborhoods. In
fact,
the totalnumberof pixels neededto build all possible contexts
is
fairly
small. This can be seenby
forming
the union of all possible context bits. Whendoing
this the adaptive pixelshould be ignored because it must be handled separately, and the two line base layer
templateshouldbeignoredaswillbeexplainedlater. It
is
easytoseethat theresultingunion
is
threepixelshigh for boththelowresolutiondataandthehighresolutiondata.3.1.1
Building
Columns
ofThree Pixels
To facilitate
building
a contextword, it is useful to group the pixels into columns ofthree pixels. Figure 14 shows how the three pixel values are arranged within a byte.
Partofthereasonfor
doing
thisis because itcanbe done very quickly andeasily. Themainreason,
however,
is thatonceit is donethesecolumns canbe
veryuseful in building
context wordsforboththehighandlowresolutionpixelsas showninthenext section. 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 stripeofoneresolu-Bits
3-7
Bit 2
Bitl
BitO
0
Unused
(0)
Pixel
from
the currentline
-2
Pixel
from
thecurrentline
-1
Pixel
from
thecurrentline
Figure 14
Pixels
stored as a column ofthreeunsigned char pixels
[STRIPE_HEIGHT]
[LINE_WIDTH]
; intline;
register int
i;
register
long
*current_line;
registerlong
*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
15Code
fragment for
columnizing
pixelstionlayer. Afterthe
loop
is
completed, eachbyteof thepixels array willholdthreepixelsintheformatshownin figure 14.
Initially,
previous_line points the the last line ofthe previous stripe which is already in the threepixel format (at the