Rochester Institute of Technology
RIT Scholar Works
Theses
Thesis/Dissertation Collections
1988
Binary image compression using run length
encoding and multiple scanning techniques
Frank J. Merkl
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 contact
Recommended Citation
Rochester InstItute of Technology
School of Computer ScIence and Technology
Binary Image CompressIon Using Run Length Encoding
and MultIple Scanning Techniques
by
Frank
J. Merkl
A thesis,
submitted to
The Faculty of the School of Computer ScIence and Technology,
In partial fulfillment of the requirements for the degree of
Master of Science in Computer Science
Approved by:
Peter G.
Anderson
Professor Peter
G. Anderson
Chris Comte
Professor Chris Comte
Rodger W.
Baker
Professor Rodger W. Baker
Title of Thesis:
Binary Image Compression Using Run Length
Enc
oding
And Hultiple Scanning Techniques
I
,
Frank
J
.
Merkl
,
hereby grant permission to
the Wallace ftemorial Library
,
of RIT,
to reproduce my thesis in
whole or in part.
Any reproduction will not be for commercial
use or profit.
...IIXIXJ ..IIUIII ..tuim
.mm, ..mii... ..juuc nin
Kufitin mi. iiiitiitiKX tn.
.jmiiiiiuxtiitii .niiiiiiiiimimirin ..1111tin tint unit ii
ntrutir-txttTXFftx-. Duuiitnin o
...mxxrxm ..DtlUI!
jorirzi) muon tintiuuiira.,
ininuurj..
TABLE
OF
CONTENTS
Abstract
1.
Introduction
1
1.1
Problem
Statement
1
1.2
Background
1
2.
Related
Work
5
3.
Image
Compression
9
3.1
Digital/Binary
Images
9
3.1.1
Image
Characteristics12
3.1.2
Image
Generation
14
3.2
Scanning
Techniques
15
3.2.1
Horizontal
Scanning
16
3.2.2
Vertical
Scanning
19
3.2.3
Perimeter
Scanning
19
3.2.4
Quadrant
Scanning
19
3.2.5
Hilbert
Curve
Scanning
21
3.3
Encoding
Techniques
22
3.3.1
Run
Length
Encoding
23
3.3.2
Huffman
Encoding
25
3.4
Decoding
Techniques
29
4.
ISC
System Architectural
Design
30
4.1
System
Configuration
30
4.2
Design
Implementation
Features
34
4.3
Configuration
andControl
Options
35
5.
ISC
System
Module
Designs
38
5.1
Main
Program
38
5.2
ImageScanning
Routines39
5.3
Run
Length
Encoding/Decoding
Routines
40
5.4
Huffman
Coding
Routines
42
5.5
Auxiliary
Routines
43
6.
Verification
andValidation
45
6.1
Test
Images
45
6.2
Overscan
48
6.3
Huffman
Coding
49
6.4
Regionalism
51
7.
Conclusions
56
7.1
Overall
Conclusions
56
7.2
Additional
Remarks
61
7.3
Future
Enhancements
andDirections
62
Glossary
Bibliography
Appendices
Abstract
While
runlength
encoding
is
a populartechnique
for
binary
image
compression,
a raster(line
by
line)
scanning
technique
is
almost always assumed and scant attentionhas
been
givento
the
possibilities ofusing
othertechniques
to
scan an
image
asit
is
encoded.This
thesis
looks
atfive
different
image
scanning
techniques
andhow
their
relationship
to
image
features
andscanning
density
(resolution)
affects
the
overall compressionthat
canbe
achieved with runlength
encoding.This
thesis
also comparesthe
performanceof run
length
encoding
with an application ofHuffman
coding
for
binary
image
compression.To
realizethese
goals a complete system of computer
routines,
the
Image,
Scanning
andCompression
(ISC)
System
has
been
developed
andis
now available
for
continued researchin
the
area ofbinary
image
compression.
ACM
Classification
Codes:
I.
4
IMAGE
PROCESSING
Chapter
1
Introduction
1. 1
Problem
Statement
This
thesis
exploresthe
effectiveness ofusing
dif
ferent
scanning
techniques
to
compress atwo-dimensional,
binary
graphicsimage
using
runlength
encoding.It
examinesthe
inter-relationships
between
runlength
encoding,
scanning
techniques,
scanning
densities
andimage
features
asthey
affect
the
overallimage
compression.It
also contrasts runlength
encoding
with an application ofHuffman
coding
for
binary
image
compression.In
orderto
observethese
relationships,
to
verify
hypotheses,
andto
make general observations
aboutbinary
image
compression,
a complete system ofcomputer
image
processing
routines,
the
Image
Scanning
andCompression
(ISC)
System,
has
been
developed.
1
.2
Background
The
explosive growthin
personalcomputers,
computernetworks and computer storage
media,
has
prompted astrong
interest
in
the
processing
ofimages
asdata,
just
astext
and quantitative values
have
been
processed asdata
sincethe
inception
of computers.One
very
crucial differenceis
the
sometimes enormous amounts of
data
space requiredto
a paper
document
or a videoscreen,
whenit
is
viewed as apurely
visualimage,
unrestricted asto
content.These
spacerequirements
have
a majorimpact
onboth
the
storage andtransmission
ofimages.
To
process a visualimage
or pictureit
is
first
necessary
to
resolveit
into
individual
picture elements calledpixels
(also
called pels).Each
pixel represents a smallunit of
image
area.The
image
canthen
be
scanned,
pixelby
pixel,
with each pixel's color andlight
intensity
represented
by
one or morebits
of computer storage.The
resultis
adigital
picture ofthe
original sourceimage.
For
this
thesis,
pixels willonly
assume one oftwo
values,
0
or1,
representing
white orblack,
respectively.Consequently,
each pixel value can
be
representedby
onebit
of computerstorage.
A
digital
picture ofthis
type
is
called abinary
picture,
orsimply
abinary
image.
An
8
1/2
X
11
inch
document
with adefined
resolution of200
pixels perinch
requireshalf
a megabyte of computerstorage as a
binary image;
at400
pixels perinch,
two
megabytes
are required.To
reducethese
huge
memory
demands,
encoding
techniques
arefrequently
employedto
compress anim
age with either no
loss
or whatis
termed
an "acceptable"loss
in
its
information
content.Corresponding
to
these
two
conditions are
two
major categories ofdata
compressiontech
also called
redundancy
reductiontechniques,
remove redundancy
from data
in
such away
that
it
canbe
later
inserted
andno
information
is
lost
[LYNCH].
Irreversible
techniques,
onthe
otherhand,
achieve much greater compression atthe
costof an
acceptable,
but
irrecoverable,
loss
in
the
averagein
formation
content ofthe
data;
its
"entropy"is
reducedand,
consequently,
irreversible
techniques
arefrequently
referredto
asentropy
reductiontechniques.
The
entropy
of animage
may
be
viewed asthe
averagein
formation
content of "messages" obtainedby
partitioning
the
image
into
disjoint
sets of pixels.When
the
compression ofan
image
precludesits
exactrestoration,
the
averageinfor
mation content of
the
messagesthat
canbe
obtainedfrom
the
image
afterit
has
been
decompressed
is
less
than
before
it
was compressed.
This
thesis
willonly
be
concerned with reversible compression
techniques
and sothe
image
entropy
willbe
preservedin
the
compression process.One
ofthe
simplest of all reversibledata
compressiontechniques
is
called runlength
encoding.In
runlength
encoding
repeateditems
in
adata
stream are replacedby
acount of
the
items
and,
usually,
oneinstance
ofthe
item
it
self.
The
longer
the
runs,
the
more effectivethe
compression.
Run
length
encoding
is
particularly
effectivefor
im
age compression since
many
images
aredominated
by
aback
The
simplicity
of runlength
encoding
stemsprimarily
from
the
fact
that
it
need not assumeany
image
structure orinter-relationship
between
image
pixels asdo
many
ofthe
more sophisticated
encoding
schemes.Although
allimage
pixels must
be
scannedonce,
runlength
encoding
imposes
no restriction
onthe
sequencein
whichthey
are scanned.Conse
quently,
the
scanning
andencoding
processes canbe
relatively
independent
andthe
selection ofthe
scanning
technique
for
any
givenimage
is
virtually
unrestricted.Two
important
application areasfor
the
compression ofbinary
images
that
use runlength
encoding
arefacsimile
transmission
and graphicsimage
storage and retrieval systems.
For
facsimile,
any
reductionin
data
volumedue
to
compression
easily
translates
into
cost savingsin
reducedChapter
2
Related
Work
The
simplicity
andintuitiveness
of runlength
encoding
makes
its
origindifficult
to
trace
to
any
oneindividual.
Several
variants existbut
a schemedescribed
by
G.
Held
[HELD]
that
combinesboth
runlength
values and unencodedsource
data
in
the
same output stream appearsto
be
the
mostcommon.
In
this
scheme aspecial,
reserved character or symbol
in
the
output streamis
usedto
indicate
that
the
nexttwo
data
items
(usually
bytes)
are a source characterfol
lowed
by
a run valueindicating
the
number of consecutivetimes
that
source characteroccurs,
atotal
ofthree
bytes
in
all.
Encoding
would notbe
worthwhile,
and wouldbe
precluded
(i.e.,
the
special character would notappear),
unlessthe
number of repeated occurrences of
the
source characterexceeds
3.
For
example,
if
the
special characteris
"#"then
the
character sequence AAAAABBCCCCCCCCC wouldbe
encoded as#A5BB#C9,
a50%
reductionin
size.This
type
of schemeis
essential when
the
average run sizein
the
input
data
streamis
relatively
smallas,
for
example,
withtext
wherethe
only
runs
usually
worthencoding
arethose
madeup
of space characters.
For
binary
graphicsimages,
wherelarge
runs of onecolor or
the
otherusually
dominate,
this
schemehas
severaldisadvantages:
(1)
adesignated
special characteris
re(3)
encoding
anddecoding
routines arerelatively
complex.A
two-dimensional
runlength
encoding
schemefor
generalimage
compression(not
necessarily
binary
images)
has
been
developed
by
B.
Pracht
and K.Bowyer
[PRACHT]
.This
scheme(actually
two
separate schemes) encodes eitherlargest
overlapping,
orlargest
non-overlapping,
rectangularblocks
ofpixels of
the
same colorby
their
corner coordinates.Both
schemes,
however,
rely
on someway
ofmarking
pixels as either
processed or unprocessed asthe
image
is
encoded.Since
pixels
in
binary
images
are representedby
bits,
which canonly
assumetwo
values,
there
is
noway
to
mark a pixel ashaving
already
been
scanned withoutintroducing
asecondary
array.
A
schemefor
compressing
binary
images
whichdoes
notuse run
length
encoding
has
been
pursuedby
E.
Davies
and A.Plummer
andis
based
on still earlier workby
Rosenfeld
andPflatz
[DAVIES].
In
this
approach abinary
image
is
reducedto
a minimal set of non-background points whoseinteger
values are equal
to
their
distance
from
the
nearestback
ground point.
This
provideshigh
compressionfor
certaintypes
ofimages
(a
circle couldbe
reducedto
a single pointwith a value equal
to
the
radiusin
pixels)but
the
encoding
and
decoding
algorithms are quite complexin
comparisonto
Still
another approachto
binary
image
compression,
presented
by
M.
Kunt
and0.
Johnsen,
is
known
asblock
coding
[KUNT].
In
this
scheme,
fixed
size,
rectangularblocks
ofpixels are encoded
using
variablelength
code words which arebased
onthe
frequency
of occurrence of eachblock
configuration.
For
blocks
larger
than
3x3
pixels(512
possibilities),
optimumHuffman
coding
soonbecomes
impractical,
so asub-optimum
coding
schemeis
introduced.
Since,
in
mostim
ages,
the
solidbackground
block
occurs mostoften,
in
the
sub-optimum
coding
schemethis
block
configurationis
simply
assigned
the
code word0.
All
other configurations are assigned
fixed
length
code wordsbeginning
with1
followed
by
the
block
configurationitself
represented as abit
configuration.
For
example,
a3
x3
pixelblock
in
a"plus
sign"configuration would
be
representedby
the
code word1010111010.
Sub-optimum
block
coding
schemes are simpleto
implement
andhave
provedto
be
very
efficient with averagecode word
lengths
approaching
(minimally)
those
generatedby
optimum
Huffman
coding
[KUNT].
The
International
Telegraph
andTelephone
Consultative
Committee
(CCITT)
has
proposed a standardfor
one-dimensionalcompression of
binary
images
for
facsimile
transmission
whichspecifically
recommendsthe
use of runlength
encoding
[CCITT].
Instead
oftransmitting
run valuesdirectly,
the
CCITT standard goes a
step
further,
specifying
that
the
runtechnique
withfixed
code words.Tables
ofthe
fixed
codewords are
included
in
the
standard.A
modifiedHuffman
coding
technique
is
required sinceit
wouldbe
impractical
to
try
to
generate Huffman code wordsfor
all ofthe
possiblerun values
that
could occur.The
CCITT
has
also proposed a standardfor
two-dimensional,
binary
image
compression schemes whichroughly
specifies
that
only
the
positions of pixelsthat
have
changedcolor
from
the
previously
scannedline
be
transmitted.
This
and other
two-dimensional
encoding
schemes exploitthe
fact
that
in
mostimages,
with areasonably
high
resolution(scan
ning
density),
few
pixels change colorfrom
line
to
line.
Both
the
one-and
two-dimensional
compression schemes proposed
in
the
CCITT
standard assume aline
by
line
rasterscanning
technique.
Both
schemes are expectedto
eventually
Chapter
3
Image
Compression
3
.1
Digital/Binary
ImagesImage
compressiontechniques
work withdigital
images
which
have
usually
been
createdfrom
original sourceimages,
such as paper
documents
or photographs.They
are created either
priorto,
orsimultaneously
with,
the
compression process
itself.
A
digital
image
is
simply
a collection of quantized
valuesrepresenting
the
color andlight
intensity
ofthe
originalimage
at points(pixels)
selected or scannedin
a grid-like
fashion.
The
quantization process convertsthe
continuous pixel magnitudes
into
afixed,
finite
set ofmag
nitude
levels
each of which canbe
representeddigitally by
one or more
bits
of computer storage.A
digital
image
couldalso represent a video
terminal
screenimage
in
which casequantization would
normally
notbe
necessary.A
certain amount ofinformation
is
almost alwayslost
from
the
originalimage
as a result ofthe
quantization process.
Some
pixels willbe
defined
on units of area ofthe
original
image
that
are nottotally
of one color(i.e.,
onedges)
forcing
the
image
scannerto
make adecision
whichPixels
ofdigital
images
that
exhibit agray
scale require multiple
bits
to
representthe
various shades of color(brightness)
from
solid whiteto
solidblack.
For
example,
an
image
with8
defined
levels
ofbrightness
requires3
bits
to
representthe
value of each pixel.In
contrast,
the
pixels of a
binary
digital
image
only
assumetwo
colorvalues,
black
orwhite,
andhence
each pixel's value canbe
represented
by
a singlebit
of computer storage.An
image
represented
in
this
way
is
saidto
be
bit-mapped.
All
ofthe
digital
images
consideredby
this
thesis
arebinary
images.
To
create abinary
digital
image
from
an original sourceimage,
such as a paperdocument,
the
document
is
scanned at adensity
measuredin
pixels perinch,
by
a scannerthat
measures
the
intensity
of reflectedlight.
The
analog
output ofthe
scanneris
putthrough
abilevel
quantization processwhich uses a
fixed
threshold
valueto
classify
the
scannersignal as
black
(level
1)
whenit
is
less
than
or equalto
the
threshold,
and white(level
0),
otherwise.Specifically,
the
analog
scanner outputf(x,y)
is
quantizedinto
the
bilev
el signal
b(x,y)
according
to
the
following
rule:b(x,y)
=1
if
f(x,y)
<=t
=
0
otherwisewhere
t
is
the
threshold
level
and x andy
arethe
pixel'scoordinates
[TING].
A dark
pixel withlittle
light
reflecrepresented
by
a1.
The
selection ofthe
"best"threshold
value,
t,
for
any
givenimage
is
of criticalimportance:
too
low
andimage
detail
is
lost,
too
high
andfalse
detail
is
introduced.
For
a givenimage
the
information
loss
from
bilevel
quantization
is
greaterthan
that
from
gray
scale quantization
andusually
resultsin
someimage
distortion.
Two
methods used
to
minimizethis
distortion
are:(1)
majority
logic
smoothing,
wherethe
"smoothed"value of a pixel
is
setto
black
when morethan
half
ofthe
pixelsin
a neighborhooddefined
aroundit
areblack;
and(2)
logical
smoothing,
wherea pixel's smoothed value
is
determined
by
the
presence or absence of certain configurations of
the
black
and white pixelsin
a neighborhood aroundit
[TING].
For
this
thesis,
it
is
assumedthat
images
to
be
scannedand compressed
already
residein
abit-mapped
storage area.Consequently,
any
scanning
process requiredto
resolve andquantize an original source
image
into
binary
valued pixels(to
createthe
binary
image)
is
consideredto
be
a pre-scan.A
pre-scan wouldbe
requiredfor
real world originalimages,
such as paper
documents
orphotographs,
but
would notbe
necessary
if
the
originalimage
were a monochrome videoter
minal screen.
In
any
case,
the
term
"original
image" will3.1.1
Image
Characteristics
Specifically,
for
this
thesis
the
originalimages
considered
for
scanning
andencoding
are restrictedto
having
the
following
characteristics:(1)
Images
canbe
representedby
two-dimensional
grids of
equally
spaced pixels.(2)
Image
colors areblack
and whiteonly
(no
gray
scale)
.(3)
Images
are of a graphicsnature,
madeup
ofregions of one or more pixels of
the
samecolor and unrestricted as
to
shape.(4)
Images
are square with sidelength
equalto
a power oftwo.
This
restrictionis
simply
to
maintain a properbalance
between
theory
andprogramming
andis
really
only
arequirement
for
two
ofthe
five
scanning
techniques
to
be
presented.Graphics
images
are madeup
simply
of regions ofpixels,
no symbols are
defined.
Typical
graphicsimages
arecharts,
graphs,
posters,
maps,
drawings,
etc.Text
may
alsobe
in
cluded
but
only
whenthe
text
is
not expectedto
be
inter
An
important
advantagein
problem simplification resultsfrom
the
restrictionto
two
image
colors:in
the
compressedrepresentation of an
image,
alternate run values canrepresent alternate colors and
there
is
no needto
store aninstance
ofthe
coloritself.
There
is,
ofcourse,
a requirement
to
identify
which coloris
representedby
the
first
run value.
This
simplificationdoes
notlessen
the
essenceof
the
problem and an extensionto
any
number of colors canbe
achievedby
simply
following
each run value with a valueindicating
the
particular colorthe
run represents.Also,
although not pertinent
to
this
thesis,
by
storing
only
runvalues,
the
polarity
ofthe
entireimage
canbe
reversed upondecompression
by
simply
changing
the
defined
color ofthe
first
run value.No
attempthas
been
madein
this
thesis
to
standardizeon an
8
1/2
x11
inch
or a similar sized squaredocument.
Instead,
the
test
images
are perceivedto
be
either small(square)
windowsinto
full-size
documents
or videoscreens,
or
full-size
images
in
their
own right.The
perception ofwindows permits
the
simulation ofhigher
scandensities
than
could
reasonably
obtained without an actual scanner.For
example,
atest
image
labeled
"text"(see
AppendixA-9
)
consists of
three
scriptletters
in
a64
x64
pixelimage
area.In
a standardtypeset
pagethese
three
letters
wouldtake
up
about
3/16
of aninch,
sothe
test
image
simulates a small340
(i.e.,
64
x16/3)
pixels perinch.
Although
the
highest
input
scanning
density/resolution
for
the
test
images
usedin
this
thesis
was64
x64
pixels(4,096
pixels),
eachtest
image
was scaledup
to
128
x128
pixels
(16,384
pixels)for
one series of compression runs.The
64
x64
input
scanning
density
was not alimitation
ofthe
ISC
system,
but
a practicallimit
for
manually
designing
and
keyboarding
the
test
images
in
the
absence of a realfront-end
scanner.By
way
ofcomparison,
a standardtelevi
sion screen
has
525
lines
of512
pixels each andthe
newIBM
graphics
standard,
VGA,
displays
640
x480
pixels(in
16
colors) on a monitor screen.
The
CCITT
recommended resolution
standardis
1728
pixels per215
millimeter scanline
(approximately
200
pixels/inch)horizontally
and3.85
scanlines
per millimeter(approximately
100
pixels/inch) vertically.
3.1.2
Image
GenerationThe
ISC
system usestest
images
from
three
sources:(1)
Directly
from
the
input
terminal
keyboard
(simulating
a realtime
scanning
device).
(2)
Using
the
contents of a storedimage
file,
initially
createdby keyboard,
scanner or(3)
Selected
from
a set ofinternally
generatedtest
images
ofbasic
shapes.By
means of(1)
or(2),
virtually
any
image
couldbe
madeavailable
to
the
scanning
andencoding
routines.An
ISC
systemscaling
routineautomatically
scales aninput
or generatedimage
to
a preselected systemimage
size,
specified
in
pixels(see
Section4.3).
3
.2
Scanning
Technigues
As
previously
mentioned,
scanning
for
pixel quantizationand
scanning
for
compression are viewed as separateprocesses.
Since
this
thesis
is
concernedonly
withthe
latter,
it
will alwaysbe
assumedthat
scanning
for
quantization
has
preceded oris
being
performedsimultaneously
(and
transparently)
withscanning
for
compression.Consequently,
henceforth,
wheneverthe
term
scanning
is
used,
it
will meanscanning
for
compression.The
most commontechnique
for
scanning
images
is
from
left
to
right,
top
to
bottom,
andis
called raster orhor
izontal
scanning.However,
if
animage
is
being
scannedfor
compression
using
runlength
encoding,
there
need notbe
any
restriction on
the
sequencein
whichthe
image
pixels are actually
scanned.In
general,
for
any
givenimage,
different
compression.
For
example,
the
number of runs(consecutive
pixels of
the
same color) encounteredby
rasterscanning
animage
consisting
of a single verticalline
(any
thickness)
is
equal
to
two
times
the
number of scanlines,
plus one. Simply
changing
to
verticalscanning,
top
to
bottom,
left
to
right,
reducesthe
number of runsto
three,
regardless ofthe
number of scan
lines
(see
Figure
1).
Besides
horizontal
andvertical
scanning,
otherscanning
techniques
canbe
used withrun
length
encoding,
eachachieving
adifferent
degree
ofcompression,
as willbe
shown.A
set offive
scanning
techniques
have
been
implemented
in
the
ISC
system.Each
technique
follows
its
own uniquepath
in
scanning
animage,
pixelby
pixel.3.2.1
Horizontal
Scanning
Horizontal
image
scanning,
usually
called raster scanning,
requiresthat
animage
be
scanned,
pixelby
pixel,
from
left
to
rightby
position,
andfrom
top
to
bottom
by
line
(see
Figure
2).
A
variantis
to
scan alternatelines
from
left
to
right andthen,
onthe
return,
from
rightto
left.
This
wouldprobably
provide aslightly
better
compressionfor
run
length
encoding
(since
the
scanner would alwaysbe
scanning
adjacent pixels)but
has
notbeen
explored so asto
re3
>
5
r7
9
11
13
^
15
^
/^77
/
z
A
/
>/
/
/
/
/
/
/
/
',
/
/
12
10
/
14
/
/
^ /
/
/ */
/^.
/
/
/
>
/
/
> /
/
/
>
/
^
17
Horizontal
Scanning
VW<
Vertical
Scanning
zl
Horizontal
Scanning
(Vertical
Scanning
at90)
Perimeter
Scanning
Quadrant
Scanning
HilbertScanning
Image
Scanning
Techniques at8
X8
Pixels
Figure
2
-18-3.2.2
Vertical
Scanning
Vertical
scanning
requiresthat
animage
be
scannedfrom
top
to
bottom
by line,
andfrom
left
to
rightby
position.Vertical
scanning
canbe
viewed assimply
a variant ofhor
izontal
scanning
withthe
orientation of eitherthe
image
orthe
scanner shiftedby
90
degrees.
This
slight changein
orientation,
however,
can resultin
dramatic
differences
in
the
compression achievedfor
certainimages.
3.2.3
Perimeter
Scanning
Perimeter
scanning
is
based
onscanning
the
perimeter ofan
image,
edgeby
edge,
continually
shrinking
in
untilthere
are no
longer
any
pixelsleft
to
scan.Edges
are scanned sothat
consecutive pixels are always adjacent:top
(left
to
right),
right(top
to
bottom),
bottom
(right
to
left)
andleft
(bottom
to
top)
. As each edgeis
scannedit
is
effectively
choppedoff,
eventually
reducing
the
image
to
nothing
(see
Figure
2).
Perimeter
scanning
canbe
very
effectivesince most real world
images,
paper and videoscreens,
have
some
kind
ofborders
madeup
ofbackground
pixels.Perimeter
scanning
is
also not constrainedto
squareimages.
3.2.4
QuadrantScanning
Quadrant
scanning
involves
scanning
animage,
whichis
in
progressively
larger
andlarger
quadrants(see
Figure
2).
It
is
relatedto
the
construction ofimage
data
structurescalled quadtrees which are created
in
the
reverse manner:by
recursively
decomposing
a squareimage
into
smaller andsmaller quadrants until each quadrant contains
only
pixels ofa single color
[SAMET].
Quadrantscanning,
as presentedin
this
thesis,
uses atechnique
based
onMorton
sequencing
[LAUZON]
.Morton
sequencing
wasfirst
introduced
in
1966
by
G.
M.
Morton
ofIBM
andis
a cellnumbering
system which attemptsto
place cellsthat
are nearto
each otherin
two-dimensional
space,
closetogether
in
one-dimensional space.It
assignsconsecutive numbers
to
cells,
beginning
withzero,
suchthat,
in
the
number'sbinary
representation,
the
odd numberedbits
denote
the
cell's coordinatealong
one axis andthe
even numbered
bits
along
the
other.So,
given a cell's assignednumber,
its
position canbe
obtained,
and vice-versa.For
example,
assuming
a coordinate system withthe
origin(0,0)
in
the
upperleft
hand
corner,
the
cell at position(5,3)
=(0101,0011)
wouldbe
assignedthe
Morton
sequence number27
=00011011.
Morton
sequencing
canbe
usedto
effect quadrant scanning.
If
the
numbersfrom
zeroto
the
total
number ofimage
pixels,
minusone,
are consideredto
be
Morton
sequenceeven numbered
bits
(i.e.,
bits
are numberedb7,...,b0)
desig
nated
to
representimage
line
andposition,
respectively,
then
the
scan paththrough
the
image
willbe
exactly
the
sameas
if
the
image
werebeing
coveredby
larger
andlarger
quadrants
.3.2.5
Hilbert
Curve
Scanning
A
Hilbert
curve,
also called aPeano
curve or a continuous space
filling
curve,
is
a curve whosediscovery
is
credited
to
mathematicianDavid
Hilbert.A
Hilbert
curvetraces
an unbroken paththrough
a square matrix of cellspassing
through
each cellonly
once and alwayspassing
to
anadjacent cell
(top,
bottom,
left
orright),
but
notto
adi
agonal cell
(see
Figure
2).
It
differs
from
many
other unbroken
path curvesin
that
it
exhibits astrong
sense of regionalism,
totally
exhausting
a regionin
both
dimensions
asit
spreads acrossthe
entireimage.
After
hilbert
scanning
has
scannedthe
first
M pixels of animage,
it
willhave
to
tally
exhausted a region with adiameter
equalto
the
squareroot of
M.
As
with quadrantscanning,
Hilbert
curvescanning
requires
that
animage
be
square andhave
a sidelength
equalto
a power of2.
Because
horizontal
and verticalscanning
operate ononly
one
line
(or
column) at atime
they
are classified asone-dimensional
scanning
techniques.
Quadrant
andhilbert
scanscanning
is
something
of ahybrid
and cannotreally
be
classified as either.
3.3
Encoding
Techniques
The
goal ofimage
compressionis
to
representthe
infor
mation content of an
image
in
less
space(as
measuredin
bits)
then
the
image
requiresin
its
naturalform
(as
measured
in
bits
representing
pixel values).Encoding
is
the
process
that
brings
aboutthis
transformation.
The
originalimage
is
then
restoredfrom
its
encoded representation priorto
display.
In
this
thesis
two
types
ofencoding
are explored: run
length
encoding
andHuffman
(en)coding.
The
principle area of
interest
is
runlength
encoding
withHuff
man
coding
providing
abasis
for
comparison.The
effectiveness ofimage
compressionis
expressed as aratio
relating
the
number ofbits
neededto
store animage
before
compression andthe
number ofbits
needed afterit
has
been
scanned and encoded.Specifically,
the
compression ratio
(C.
R.
)
is
defined
as:C.
R. =bits
in
originalimage
/
bits
in
compressedimage
The
higher
the
compression ratiothe
better
the
compression.A
compression ratio of3
meansthat,
onthe
average,
3
pixelsin
the
originalimage
are representedby
1
bit
in
the
compressed
image.
The
ISC
system calculates anddisplays
the
compressed.
3.3.1
Run
Length
Encoding
In
the
ISC
system,
as animage
is
scannedit
is
simultaneously
runlength
encoded,
producing
a sequence ofinteger
run values which are
then
stored as aninteger
array.Each
run value represents
the
length
of a run of eitherblack
orwhite pixels and alternate run values represent alternate
colors .
Although
not a restriction ofthe
ISC
system,
for
this
thesis,
the
default
storage allocationfor
each run valueis
an
8-bit
byte
with multi-byte constructionsfor
run valueslarger
than
255.
Consequently,
runlength
encoding
animage
would not
be
of much value unlessthe
average run valueis
greater
than
8.
Rather
than
mix run values and unencodedruns of pixels
in
the
compressedimage
representation(see
Chapter
2),
the
runlength
encoding
routine ofthe
ISC
systemhas
been
designed
to
terminate
encoding,
andto
storethe
entire
image
unencoded,
wheneverthe
pointis
reached wherethe
storage space
for
the
run values will exceedthe
storagespace
for
the
image
uncompressed.It
is
recognizedthat
this
could cause a problem
if
animage,
asit
is
being
encoded,
is
simultaneously
being
transmitted,
ratherthan
just
being
stored,
and special retransmit procedures wouldhave
to
be
in
Since
in
the
compressed representation of animage,
alternate
run values represent alternate colors(no
instance
ofthe
coloritself
is
stored),
a problem arises onhow
to
indi
cate which color
is
representedby
the
first
run value.The
solution proposed
in
the
CCITT
standardis
to
always assumethe
first
run value representsthe
color white andto
setit
equal
to
zeroif
the
first
colorhappens
to
be
black.
In
the
ISC
system,
however,
the
number zerois
already
being
usedfor
multi-byte run values(see
Section
4.2).
Another
problemis
that,
althoughthe
ISC
systemin
its
present configuration compresses an
image
using
allfive
scanning
techniques/routines,
in
practical applicationsonly
one,
but
any
one,
mightbe
used.Consequently,
the
identity
of
the
scanning
technique
that
has
been
usedto
scan animage
must
be
somehow preserved withthe
image's
compressedrepresentation so
it
canbe
properly decompressed.
Also,
aswas
previously
mentioned, animage
may
have
no compression atall
and,
if
so,
this
too
mustbe
indicated.
To
satisfy
the
aboverequirements,
the
first
element ofeach compressed
image's
run valuesarray
has
been
designated
to
indicate
both
the
scanning
technique
used,
andthe
colorof
the
first
run value(which
is
nowthe
secondarray
element).
The
specific valuesthe
first
array
elementmay
hold
Value
Scanning
Technique
First
Color
0
Unencoded
Either
1
Horizontal
White
2
Horizontal
Black
3
Vertical
White
4
Vertical
Black
5
Perimeter
White
6
Perimeter
Black
7
Quadrant
White
8
Quadrant
Black
9
HilbertWhite
10
Hilbert
Black
3.3.2
Huffman
Coding
Huffman
coding
is
atechnique
for
data
compressionin
troduced
by
D.
A.
Huffman
in
1952.
In
Huffmancoding,
fixed
size
data
elements(e.g.,
symbols,
characters,
numericvalues,
etc.) are encodedby
assigning
code wordsthat
vary
in
sizeaccording
to
eachdata
element'sfrequency
or probability
of occurrence.Data
elementsthat
occurfrequently
are assigned short code words while
those
that
occurinfre
quently
are assignedlong
code words.Huffman's
technique
optimizes
the
selection ofthe
code words sothat
the
streamof encoded
data
elements willbe
of minimumlength.
For
any
given set of
data
elements andcorresponding
frequency
dis
but
the
compression achievedis.
A
key
feature
ofHuffman
coding
is
that
no code wordis
the
beginning
of alonger
codeword which means a coded
data
stream canbe
instantaneously
decoded.
If
the
data
elements are combined andHuffman
codedin
blocks,
the
average number ofbits
to
encode eachdata
element
is
reduced and approaches alower
bound
known
asthe
entropy
ofthe
information
source(with
the
blocks
then
considered as messages
from
the
source).The
lower
bound
is
attained
only
if
the
probabilities of occurrencefor
the
blocks
are all negative powers of
2
and,
ofcourse,
sumto
1
(e.g.,
1/2,
1/4,
1/8
and1/8).
This
is
notnormally
the
case.The
entropy
of aninformation
sourceis
calculated asfollows
[CORBIN]:
If
the
probability
of occurrence of adata
element
is
p,
then
the
number ofbits
b
to
encode
it
is
givenby:
b
=f(-log2
p)where
f(x)
is
the
closestinteger
>= x.(This
resultis
due
to
early
workin
infor
mation
theory by
C.
Shannon
atAT&T.)
For
example,
in
English
text
the
probability
of
the
letter
"e"b
=f(-log2
0.13)
=f(2.94)
=3
bits
The
entropy,
H,
whichis
the
average number ofbits
to
encode eachdata
element,
is
then:
H
=-Summation
[
p(i) *log2
p(i)]
bits
where p(i)
is
the
probability
of occurrence ofthe
i-th
data
element andthe
summationis
over alldata
elements.The
entropy
for
the
English alphabet
andthe
space characterin
generaltext
is
about
4.1
bits.
Although
blocking
reducesthe
average number ofbits
to
encode each
data
element,
it
exponentially
increases
the
number of possible code
words,
quickly
resulting
in
both
large
increases
in
processing
time
and avery
large
code wordlookup
table.
For
image
compression,
Huffman
coding
canbe
usedto
directly
encode smallfixed
sizeblocks
ofpixels,
asis
done
in
this
thesis,
orit
canbe
usedin
conjunction with runlength
encoding
to
encodethe
runvalues,
asis
specifiedin
the
CCITT
recommended standard[CCITT].
Pixel
blocks
canbe
directly
encodedusing
the
standardHuffman
algorithm[LYNCH]
based
onthe
frequency
of occurrence of eachblock
configuration.
The
optimum code words soderived
canthen
be
usedto
encode
the
image,
usually
by
table
lookup.
These codewords,
code words would
have
to
be
generatedfor
the
nextimage.
More
importantly,
the
code words mustbe
preserved and storedand/or
transmitted
withthe
image
in
orderto
be
ableto
later
decode
it.
An
alternate approachis
to
first
establish afixed
setof code words and
then
useit
to
encode all subsequentim
ages.
Fixed
code words areindependent
ofthe
image
being
encoded,
significantly
reducing
the
encoding
time
and eliminating
the
needto
store ortransmit
a separate code wordtable
with each compressedimage.
One
way
to
create a "good"set of
fixed
code wordsis
to
base
it
onthe
total
frequency
distribution
of agroup
ofimages
ofthe
sametype
asthe
target
group.Obviously,
compressionusing
fixed
code wordswould
generally
notbe
optimum. TheCCITT
recommended standard
usesfixed
code wordtables
based
onthe
results of encoding
agroup
of11
"typical"documents
[CCITT].
Blocks of
four
contiguoushorizontal
pixels,
atotal
of16
possibleconfigurations,
were codedusing
Huffman
codewords.
Both
fixed
and optimumHuffman
code words were usedto
encode alltest
images,
notonly
to
provide abasis
for
comparison
to
runlength
encoding,
but
alsoto
compareto
each other.
The
fixed
code words werederived
from
the
combined
frequency
distribution
of4-pixel
blocks
containedin
and
flowchart
(see
Appendix
A-8,
A-9
and A-10).3. 4
Decoding
Techniques
Encoding
data
for
compression wouldbe
oflittle
usewithout a
corresponding
decoding
process.Consequently,
acomplimentary
image
decompression/decoding
routinefor
runlength
encoding
is
included
in
the
ISC
system.Only
onedecompression
routineis
required sinceit
usesthe
samescanning
routinesthat
are usedto
compress animage,
but
reverses
the
process,
converting
anarray
of run valuesinto
a pixel/bit
integer
array
to
reconstruct an originalimage.
To
verify
the
integrity
ofthe
scanning
andencoding
routines of
the
ISC
system,
eachdecompressed
image
is
compared
to
the
original uncompressedimage
to
ensure an exactChapter
4
ISC
System
Architectural
DesignThe
ISC
system performsthe
basic
function
of compressing
abinary
image
by
the
application ofscanning
and encoding
techniques.
In
its
present configurationthe
ISC
systemserves
primarily
as a researchtool;
every
image
is
compressed
using
runlength
encoding
and allfive
ofthe
system's
scanning
techniques.
In
addition,
every
image
is
compressed
using
Huffman
code words.4
.1
System
Configuration
The
principle components ofthe
ISC
system(see
Figures
3a
and3b)
are:(1)
A
main(user
interface/driver)
program.(2)
A
set offive
scanning
routines.(3)
Three
image
generation methods.(4)
Run
length
encoding
anddecoding
routines.(5)
A
Huffman
coding
routine.(6)
Auxiliary
routines.Each
ofthe
five
scanning
routines uses adistinct
tech
main
Select
s canimage
\
response
F
(file)
S(scan)
G(generate)
\
/
gemmage
/
scale
Original
Image
showimage
scanemprs
scanstats
Figure 3b
Figure
3a
-31-Compressed
Imageputpixel
decode
Decompressed Image
V,
compare Original
Image
^.
huffman
hstruc
showcode
entropy
gencode
merit
Figure
3"b
-32-provided
by
means of aterminal
keyboard,
a storedfile,
oran
internal
ISC
systemimage
generation routine.The
scanning
routines provide asteady
stream of pixel coordinatesto
the
runlength
encoding
routine whichthen
produces acompressed representation of
the
image
as aninteger
array
ofrun values.
The
originalbinary
image
is
regenerated(as
abit-mapped
integer
array) wheneverits
compressed run valuesarray
is
passedto
the
runlength
decoding
routine.The
Huffman
coding
routine compresses animage
by
encoding
4-pixel
blocks
using
both
optimum(unique
to
the
image)
code words and
fixed
code words.The
routinedoes
not actually
produce a compressed representation ofthe
binary image,
instead
it
generatesboth
fixed
and optimum sets of codewords,
andthen
calculates,
if
the
image
wereto
be
compressed,
the
size ofthe
compressedimage
in
bits,
the
compression ratio and
the
compressionefficiency,
using
both
sets of code words.
The
entropy
ofthe
image
(as
aninforma
tion
source)is
also calculated.The
separation ofthe
scanning,
encoding
andimage
generation routines allows
the
ISC
systemto
be
open-ended. Additional
scanning
routines andencoding
routines can addedto
the
system withoutdifficulty,
These
canthen
investigated
rou-tines,
using
virtually any desired
image.
4.
2
Design
Implementation
Features
The
primary
data
structure ofthe
ISC
systemis
the
in
teger
array.Although
not alimit
ofthe
host
computer,
northe
ISC
system,
an8-bit
byte
was selected asthe
(simulated)
storage unit
for
allimage
arrays:original,
compressed anddecompressed.
Compressed
image
run valuesthat
exceedthe
limit
of an8-bit
byte
are storedusing
a multi-byte construction
in
the
following
manner: sincethe
value zero cannot
logically
occur as a valid run valueit
is
used as an es capecharacter,
serving
to
indicate
that
the
nexttwo
bytes
are required
to
computethe
actual runvalue;
the
first
ofthese
two
bytes
containsthe
highest
multiple of255
less
than
the
runvalue;
the
second containsthe
remainder afterdividing
the
run valueby
255.
Each
compressedimage
array
has
two
overhead elements:the
first
array
elementindicates
both
the
scanning
methodused and
the
color representedby
the
first
runvalue;
the
last
array
elementis
the
array
terminator.
The
first
is
considered
in
calculating
the
compressionratio,
the
last
is
not sinceit
may
be
implemented
in
any
number of ways ondif
ferent
systems.While
allimages,
priorto
scanning,
are perceived asone-dimensional
8-bit
integer
arrays.The
two
forms
areequivalent
in
that
the
integer
arrays are read and written ona
bit
by
bit
(i.e.,
pixelby
pixel)basis.
The
bit
value1
has
arbitrarily
been
chosento
representthe
colorblack
andthe
bit
value0
the
colorwhite;
the
color whiteis
also assumed
to
be
the
background
color.4
.3
Configuration
andControl
Options
Several
parameters(symbolic
constants)have
been
de
fined
to
provideflexibility
in
changing
the
ISC
system's runtime
"dimensions."These
are:
(1)
HPIX
andVPIX:
setthe
vertical andhorizontal
dimensions
in
pixels ofthe
originalimage.
VPIX
mustbe
equalto
HPIX
andboth
mustbe
apower of
2.
(2)
SCANSIZE: setsthe
sizein
pixels of ahorizontal
scanline
ofthe
originalinput
image.
If
SCANSIZE
is
less
than
HPIX
the
scanned
input
image
is
automatically
scaledup
to
HPIX
x VPIX.(3)
SHOWSIZE: setsthe
display
sizein
pixels ofthe
originalimage
whenthe
function
showimageis
invoked.
The
maximum SHOWSIZEis
64
x64;
if
the
originalimage
size(as
setby
HPIX
andis
scaleddown
to
fit.
(4)
ISIZE:
setsthe
maximum size ofthe
systemimage
array
elementsin
bits.
Two
additional system control variables whose values areset
by
the
user asthe
result of system prompts are showscans and showarrays.A
response of "yes"to
showscans will causepixel values
to
be
displayed
as animage
is
being
scanned.A
"yes"response
to
showarrays causesthe
integer
arraysrepresenting
the
original,
compressed anddecompressed
images
to
be
displayed.
While
these
variables areextremely
usefulfor
systemdevelopment
and researchpurposes,
their
useis
impractical
for
high
scanning
densities.
A
typical
display
for
aterminal
sessionusing
the
ISC
IMAGE SCANNING AND COMPRESSION
Select the means of providing the target image: S = Scanner or keyboard
F - Stored file
G = Generated
: F
Show scans (Y or N)? N
Show arrays (Y or N)? N
Enter file name: panda
Enter 64 lines of 64 pixels each.
Enter a 0 or space for a white pixel.
Enter a 1 for a black pixel.
Enter a * to quit.
(Missing
lines and unfilled line ends default to spaces.)* HUFFMAN CODING *
Entropy: 1.80
* OPTIMUM CODES *
Average code word: 1.86 bits Code efficiency: 0.97
* FIXED CODES *
Average code word: 1.90 bits Code efficiency: 0.95
64 X 64
HORIZ VERT PERIM QUAD HILBT HUFFO HUFFX
CR. 1.94 1.77 2.04 1.38 1.79 2.15 2.11
Bits 2112 2320 2008 2976 2288 1908 1943
Runs 261 289 250 367 281
Figure
4
-37-Chapter
5
ISC
System
Module
Designs
All
algorithms and routinesin
the
ISC
system are written
asfunctions
in