Digital Image Processing I Contents
Digital Image Processing I Contents
9 September 2010
Contents
Preface ix
2 Review of Sampling 7
2.0.1 Ideal Sampling of 1-D function . . . . . . . . . . . . . . . . . 8
2.1 Aliasing –Whittaker-Shannon Sampling Theorem . . . . . . . . . . . 11
2.2 Realistic Sampling –Averaging by the Detector . . . . . . . . . . . . 12
3 Review of Quantization 21
3.1 Quantization: A/D Conversion . . . . . . . . . . . . . . . . . . . . . 21
3.1.1 Tone Transfer Function . . . . . . . . . . . . . . . . . . . . . . 21
3.2 Quantization Error (“Noise”) . . . . . . . . . . . . . . . . . . . . . . 25
3.2.1 Signal-to-Noise Ratio . . . . . . . . . . . . . . . . . . . . . . . 28
3.2.2 Example: Variance of a Sinusoid . . . . . . . . . . . . . . . . . 29
3.2.3 Example: Variance of a Square Wave: . . . . . . . . . . . . . . 30
3.2.4 Variance of “Noise”from a Gaussian Distribution . . . . . . . 30
3.2.5 Approximations to SNR . . . . . . . . . . . . . . . . . . . . . 30
3.2.6 SNR of Quantization . . . . . . . . . . . . . . . . . . . . . . . 32
3.3 Quantization to Few Bits . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.3.1 Improved Gray Scale (IGS) Quantization . . . . . . . . . . . . 35
3.3.2 Quantizers with Memory –Error Di¤usion . . . . . . . . . . . 35
4 Point Operations 39
4.1 Geometrical Operations . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.2 Least-Squares Solution for Warping . . . . . . . . . . . . . . . . . . . 42
4.3 Common Geometrical Operations . . . . . . . . . . . . . . . . . . . . 45
4.4 Pixel Transfers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.5 Pixel Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.6 Point Operations on Single Images . . . . . . . . . . . . . . . . . . . 46
4.6.1 Image Histograms . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.6.2 Histograms of Typical Images . . . . . . . . . . . . . . . . . . 48
4.6.3 Cumalative Histogram . . . . . . . . . . . . . . . . . . . . . . 48
v
vi CONTENTS
5 Local Operations 57
5.1 Window Operators –Correlation . . . . . . . . . . . . . . . . . . . . 57
5.2 Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.2.1 Convolutions –Edges of the Image . . . . . . . . . . . . . . . 63
5.2.2 Convolutions –Computational Intensity . . . . . . . . . . . . 63
5.2.3 Smoothing Kernels –Lowpass Filtering . . . . . . . . . . . . . 64
5.2.4 Di¤erencing Kernels –Highpass Filters . . . . . . . . . . . . . 66
5.3 Nonlinear Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
5.3.1 Median Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
5.3.2 Example of Median Filter of Uniform Distribution . . . . . . . 75
5.4 Median Filter and Gaussian Noise . . . . . . . . . . . . . . . . . . . . 77
5.5 Comparison of Histograms after Mean and Median Filter . . . . . . . 79
5.6 E¤ect of Window “Shape” . . . . . . . . . . . . . . . . . . . . . . . . 79
5.6.1 Other Statistical Filters (Mode, Variance, Maximum, Minimum) 81
5.6.2 Examples of Nonlinear Filters . . . . . . . . . . . . . . . . . . 81
5.6.3 Nonlinear Filters on Images with Additive Gaussian Noise . . 82
6 Shape-Based Operations 91
6.1 Pixel Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
6.2 Image Labeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
6.2.1 Example: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
6.3 Border Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
6.4 Cascaded Morphological Operations –“Opening”and “Closing” . . . 96
6.5 Applications of Morphological Operations . . . . . . . . . . . . . . . 97
6.5.1 Noise Removal . . . . . . . . . . . . . . . . . . . . . . . . . . 97
CONTENTS vii
9 129
Preface
References
Center for Image Processing in Education: lots of links to software and images
http://www.evisual.org/homepage.html
ImageJ software for image processing and analysis in Java, evolution of NIHImage
http://rsb.info.nih.gov/ij/
Image 2000 (from NASA)
http://www.ccpo.odu.edu/SEES/ozone/oz_i2k_soft.htm
Scion Image Processing Software (for PC and MAC-OS)
http://www.scioncorp.com/frames/fr_scion_products.htm
Hypercube Image Analysis Software (for PC and MAC-OS)
http://www.tec.army.mil/Hypercube/
GIMP Image Processing Software (Gnu-IMP). for PC, MacOS, Linux
http://www.gimp.org/
Irfanview (free image processing viewer with some processing capability)
http://www.irfanview.com/
ix
x Preface
During the last two decades or so, inexpensive and powerful digital computers have
become widely available and have been applied to a multitude of tasks. By hitching
computers to new imaging detectors and displays, very capable systems for creating,
analyzing, and manipulating imagery have been constructed and are being applied
in many arenas. For example, they now are used to reconstruct X-ray and magnetic
resonance images (MRI) in medicine, to analyze multispectral aerial and satellite
images for environmental and military uses, to read Universal Product Codes that
specify products and prices in retail stores, to name just a few.
Since I …rst taught a predecessor of this course in 1987, the capabilities of inex-
pensive imaging tools (cameras, printers, computers) have exploded (no surprise to
you, I’m sure). This has produced a wide and ever-expanding range of applications
that we could not even envision in those days. To give an idea of the change over the
last two decades, consider the set of data shown below, which is copied directly from
the …rst edition of Digital Image Processing by Gonzalez and Woods:
1
2CHAPTER 1 BASIC PRINCIPLES OF DIGITAL IMAGE PROCESSING
These data represent a 64 64 5-bit image (25 = 32 gray values). This data set was
entered by hand (with only 4 mistakes) in 1988 by Ranjit Bhaskar, an imaging science
graduate student for use by students. The image was rendered using the so-called
“overstrike”routine on a line printer, where “dark”pixels were printed using several
overprinted characters and lighter pixels by sparse characters (e.g. “.”and “-”). The
subject of the image is shown on the next page:
3
Data in previous photo rendered using “overstrike” printout with line printer – this
is how we used to do it, folks!
This course will investigate the basic principles of digital imaging systems and
introduce useful applications; many simple examples will be provided to illustrate the
concepts. First, a de…nition:
Image Representation of
f [n; m]
It is more and more common to deal with images that have more than two coor-
dinate dimensions, e.g.,
After converting image information into an array of integers, the image can be
manipulated, processed, and displayed by computer. Computer processing is used
for image enhancement, restoration, segmentation, description, recognition, coding,
reconstruction, transformation
1.1 DIGITAL PROCESSING 5
2. The digital processor operates on the digital image fq [n; m] to generate a new
digital image gq [k; `], where k, `, and gq are integers. The output image may be
represented in a di¤erent coordinate system, hence the use of di¤erent indices
k and `.
3. The image display converts the digital output image gq [k; `] back into a continuous-
tone and spatially continuous image g [x; y] for viewing. It should be noted that
some systems may not require a display (e.g., in machine vision and arti…cial
intelligence applications); the output may be a piece of information. For ex-
ample, a digital imaging system that was designed to answer the question, Is
there evidence of a cancerous tumor in this x -ray image?, ideally would have
two possible outputs (YES or NO), , i.e., a single bit of information.
Note that the system includes most of the links in what we call the imaging chain.
We shall …rst consider the mathematical description of image digitizing and display
devices, and follow that by a long discussion of useful processing operations.
1.2 Digitization
Digitization is the conversion of a continuous-tone and spatially continuous brightness
distribution f [x; y] to an discrete array of integers fq [n; m] by two operations which
will be discussed in turn:
6CHAPTER 1 BASIC PRINCIPLES OF DIGITAL IMAGE PROCESSING
2 bits can represent: 004 = 0:, 014 = 1, 104 = 2:, 114 = 3:;a total of 22 = 4
numbers.
(where the symbol “4 ”denotes the binary analogue to the decimal point “.”and
thus may be called the “binary point,”which separates the ordered bits with positive
and negative powers of 2).
Review of Sampling
The process of “sampling” derives a discrete set of data points at (usually) uniform
spacing. In its simplest form, sampling is expressed mathematically as multiplication
of the original image by a function that “measures”the image brightness at discrete
locations of in…nitesimal width/area/volume in the 1-D/2-D/3-D cases:
fs [n x] = f [x] s [x; n x]
where:
f [x] = brightness distribution of input image
s [x; n x] = sampling function
fs [n x] = sampled input image de…ned at coordinates n x
The ideal sampling function for functions of continuous variables is generated from
the so-called “Dirac delta function” [x], which is de…ned by many authors, including
Gaskill. The ideal sampling function is the sum of uniformly spaced “discrete”Dirac
delta functions, which Gaskill calls the COMB while Bracewell calls it the SHAH :
X
+1
COM B [x] [x n]
n= 1
X
+1
1 h x i
s [x; n x] [x n x] COM B
n= 1
x x
7
8 CHAPTER 2 REVIEW OF SAMPLING
The COMB function de…ned by Gaskill (called the SHAH function by Bracewell).
For the (somewhat less rigorous) purpose we have here, we may consider the
sampling function to just “grab”the value of the continuous input function f [x; y] at
the speci…c locations separated by the uniform intervals x and y, where x = y:
fs [n; m] = f [n x; m y]
In other words, we are sweeping some unimportant and possibly confusing mathe-
matical details under the rug.
1 2 x
f [x] = 1 + cos + 0
2 X0
The amplitude of the function at the sample indexed by n is:
1 n x
fs [n x] = 1 + cos 2 + 0
2 X0
1 x
= 1 + cos 2 n + 0
2 X0
The dimensionless parameter Xx0 in the second expression is the ratio of the sampling
interval to the spatial period (wavelength) of the sinusoid and is a measurement of
9
the …delity of the sampled image. For illustration, examples of sampled functions
obtained for several values of Xx0 are:
x 1 1 h ni
Case I: X0 = 12 x =) = ; 0 = 0 =) fs [n] = 1 + cos
X0 12 2 6
x 1 1 1
Case II: X0 = 2 x =) = ; 0 = 0 =) fs [n] = (1 + cos [ n]) = [1 + ( 1)n ]
X0 2 2 2
x 1 1 1
Case III: X0 = 2 x =) = ; 0= =) fs [n] = (1 + sin [ n]) =
X0 2 2 2 2
4 x 3
Case IV: X0 = x =) = ; 0=0
3 X0 4
1 2 n 1 h ni
=) fs [n] = 1 + cos = 1 + cos 3
2 4=3 2 2
4 x 5
Case V: X0 = x =) = ; 0=0
5 X0 4
1 2 n 1 h ni
=) fs [n] = 1 + cos = 1 + cos 8
2 5=4 2 5
10 CHAPTER 2 REVIEW OF SAMPLING
x
Illustration of samples of the biased sinusoids with the di¤erent values of X0
listed
in the table. The last three cases illustrate “aliasing.”
The output evaluated for Xx0 = 12 depends on the phase of the sinusoid; if sampled
at the extrema, then the sampled signal has the same dynamic range as f [x] (i.e.,
it is fully modulated), show no modulation, or any intermediate value. The interval
x = X20 de…nes the Nyquist sampling limit. If Xx0 > 12 sample per period, then the
same set of samples could have been obt5ained from a sinusoid with a longer period
and a di¤erent sampling interval x. For example, if Xx0 = 34 , then the reconstructed
function appears as though obtained from a sinudoid with period X00 = 3X0 if sampled
with Xx0 = 14 . In other words, the data set of samples is ambiguous; the same samples
0
2.1 ALIASING –WHITTAKER-SHANNON SAMPLING THEOREM 11
could be obtained from more than one input, and thus we cannot distinguish among
the possible inputs based only on knowledge of the samples.
Any 1-D or 2-D function may be expressed as a unique sum of 1-D or 2-D
sinusoidal components
with (generally) di¤erent amplitudes, frequencies, and phases.
This is the principle of Fourier analysis, which determines the set of sinusoidal
components from the function. The set of amplitudes and phases of the sinusoidal
components expressed as a function of frequency are the Fourier components of the
function.
If the sinusoidal representation of f [x] has a component with a maximum spatial
frequency max , and if we sample f [x] so that this component is sampled without alias-
ing, then all sinusoidal components of f [x] will be adequately sampled and f [x]can
be perfectly reconstructed from its samples. Such a function is band-limited and
max is the cuto¤ frequency of f [x]. The corresponding minimum spatial period is
1
Xmin = max . Thus the sampling interval x can be found from:
x 1 Xmin 1
< =) x< =) x<
Xmin 2 2 2 max
12 CHAPTER 2 REVIEW OF SAMPLING
This is the Whittaker-Shannon sampling theorem. The limiting value of the sam-
1
pling interval x = 2 max de…nes the Nyquist sampling limit. Sampling more or less
frequently than the Nyquist limit is oversampling or undersampling, respectively.
1
x> =) undersampling
2 max
1
x< =) oversampling
2 max
The Whittaker-Shannon Sampling Theorem is valid for all types of sampled sig-
nals. An increasingly familiar example is digital recording of audio signals (e.g., for
compact discs or digital audio tape). The sampling interval is determined by the
maximum audible frequency of the human ear, which is generally accepted to be
approximately 20kHz. The sampling frequency of digital audio recorders is 44,000
samples 1
second
which translates to a sampling interval of 44;000 s
= 22:7 s. At this sampling
rate, sounds with periods greater than 2 22:7 s = 45:4 s (or frequencies less than
(45:4 s) 1 = 22 kHz) can theoretically be reconstructed perfectly, assuming that
f [t] is sampled perfectly (i.e., at a point). Note that if the input signal frequency is
greater than the Nyquist frequency of 22 kHz, the signal will be aliased and will ap-
pear as a lower-frequency signal in the audible range. Thus the reconstructed signal
will be wrong. This is prevented by ensuring that no signals with frequencies above
the Nyquist limit is allowed to reach the sampler; higher frequencies are …ltered out
before sampling.
1 2 x
f [x] = 1 + cos + 0
2 X0
Note that modulation is only de…ned for nonnegative (i.e., biased) sinusoids. The
analogous quantity for a nonnegative square wave is called contrast.
The biased sinusoidal signal is averaged over the detector area, e.g., the sampled
value at n = 0 is:
Z +
d0
1 2
fs [n = 0] = f [x] dx
d0 d0
2
8
> d0
>
> 1 if jxj <
Z +1
>
< 2
1 x x 1 d0 d0
= f [x] RECT dx where: RECT if jxj = =) x =
d0 1 d0 d0 >
>
2
2 2
>
> d0
: 0 if jxj >
2
14 CHAPTER 2 REVIEW OF SAMPLING
For f [x] as de…ned above, the set of samples is derived by integrating f [x] over the
area of width d centered at coordinates that are integer multiples of x:
Z n x+
d0
1 2 1 2 x
1 + cos + 0 dx
d0 n x
d0
2
2 X0
Z d0 Z n x+ d0 !
n x+
1 2 2 2 x
= dx + cos + 0 dx
2d0 n x
d0
2
d
n x 20 X0
h i x=n x+
d0
2
2 x
1 d0 d0 1 sin X0
+ 0
= n x+ n x + 2
2d0 2 2 2d0 X0 d0
x=n x
h i h i 2
x d0 x d0
1 1 sin 2 n X0
+ X0
+ 0 sin 2 n X0 X0
+ 0
= +
2 2d0 2
X0
By de…ning
x
=2 n + 0
X0
d0
=
X0
and applying the trigonometric identities:
The last multiplicative term may be simpli…ed by applying the de…nition of the special
function
sin [ ]
SIN C [ ]
1 d0 x
=) fs [n] = 1 + SIN C cos 2 n + 0
2 X0 X0
sin [ x]
SIN C [x] ; note that the value at the origin is unity, which may be
x
demonstrated via l’Hôpital’s rule.
Note that for constant functions, the period X0 = 1 and the resulting value of
the SIN C function is:
d0
lim SIN C =1
X0 !1 X0
which means that uniform weighted averaging has no e¤ect on any constant input
function. The samples of cosine of period X0 obtained with sampling interval x in
the two cases are:
1 d0 x
Realistic:fs [n] = 1 + SIN C cos 2 n + 0
2 X0 X0
1 x
Ideal: fs [n] = 1 + cos 2 n + 0
2 X0
where d0 is the width of the detector. The amplitude of the realistic case is multiplied
d0
by a factor of SIN C , which is less than unity everywhere except at the origin,
X0
, i.e., where d0 = 0 or X0 = 1. As the detector size increases relative to the
d0 d0
spatial period of the cosine ( i.e., as increases) , then SIN C ! 0 and the
X0 X0
modulation of the sinusoid decreases.
The input function f [x] has a period of 128 units with two periods plotted. It is the
sum of six sinusoidal components plus a constant:
1 1 X ( 1)n
6 1
(2n 1) x
f [x] = + sin 2 :
2 2 n=1 n 256
d0 1
SIN C = SIN C [d0 1 ] = SIN C 8 ' 0:994
X01 128
d0 3
SIN C = SIN C [d0 2 ] = SIN C 8 ' 0:943
X02 128
d0 5
SIN C = SIN C [d0 3 ] = SIN C 8 ' 0:847
X03 128
d0 7
SIN C = SIN C [d0 4 ] = SIN C 8 ' 0:714
X04 128
d0 9
SIN C = SIN C [d0 5 ] = SIN C 8 ' 0:555
X05 128
d0 11
SIN C = SIN C [d0 6 ] = SIN C 8 ' 0:385
X06 128
Note that the modulation of sinusoidal components with shorter periods (higher
frequencies) are diminished more severely by the averaging. A set of pre…ltered images
for several di¤erent averaging widths is shown on a following page. If the detector
width is 32 units, the resulting modulations are:
1
SIN C [d0 1 ] = SIN C 32 ' 0:900
128
3
SIN C [d0 2 ] = SIN C 32 ' 0:300
128
SIN C [d0 3] ' 0:180
SIN C [d0 4] ' 0:129
SIN C [d0 5] ' 0:100
SIN C [d0 6 ] ' +0:082
Note that the components with periods X04 and X05 have negative modulation,
, i.e., fmax < fmin . The contrast of those components is reversed. As shown, the
sampled image looks like a sawtooth with a period of 128 units.
If the detector size is 128, each component is averaged over an integral number of
periods and the result is just the constant bias; the modulation of the output is zero:
128
SIN C [d0 1 ] = SIN C = SIN C [1] = 0
128
7
SIN C [d0 2 ] = SIN C 128 = SIN C [3] = 0
42
1
SIN C [d0 1 ] = SIN C 170 ' 0:206
128
3
SIN C [d0 2 ] = SIN C 170 ' 0:004
128
5
SIN C [d0 3 ] = SIN C 170 ' +0:043
128
7
SIN C [d0 4 ] = SIN C 170 ' 0:028
128
SIN C [d0 5] ' 0:004
SIN C [d0 6 ] ' +0:021
Because the …rst (largest amplitude) sinusoidal component has negative modula-
tion, so does the resulting image. The overall image contrast is reversed; darker areas
of the input become brighter in the image.
Chapter 3
Review of Quantization
21
22 CHAPTER 3 REVIEW OF QUANTIZATION
response will not change for intensities above some maximum. All realistic de-
tectors are therefore nonlinear, but there may be some regions over which they
are more-or-less linear, with nonlinear regions at either end. A common such
example is photographic …lm; the TTC is the Hurter-Dri¢ eld (H&D) curve,
which is a graph of the recorded optical density of the emulsion as a function
W
of the logarithm of the input irradiance (which might be measured in mm 2 ).
Another very important example in digital imaging is the video camera, whose
TTC maps input light intensity to output voltage. The transfer characteristic
of a video camera is approximately a power law:
Vout = c1 Bin + V0
where V0 is the threshold voltage for a dark input and (gamma) is the exponent
of the power law. The value of depends on the speci…c detector but typical
values are ' 1:7 for a vidicon camera and ' 1 for an image orthicon. The
value of gamma for a digital sensor (CCD) is inherently very close to unity, but
are often modi…ed in software to approximate photographic emulsions.
The resolution, or step size b0 , of the quantizer is the di¤erence in the measured
signal at the center of adjacent gray levels. It makes little sense to quantize the
sampled signal with a resolution b0 that is smaller than the signal uncertainty due to
noise in the detector system. Thus the e¤ective number of levels is often less than
the maximum available as determined by the number of bits.
3.1 QUANTIZATION: A/D CONVERSION 23
map to gray level 59. Threshold conversion is a nonlinear operation, i.e., the thresh-
old of a sum of two inputs is not necessarily the sum of the thresholded outputs. The
concept of linear operators will be discussed extensively later, but we should say at
this point that the nonlinearity due to quantization makes it inappropriate to analyze
the complete digital imaging system (digitizer, processor, and display) by common
linear methods. This problem is usually ignored, as is appropriate for large numbers
of quantized levels that are closely spaced so that the digitized image appears con-
tinuous. Because the brightness resolution of the eye-brain is limited, quantizing to
only 50 levels is satisfactory for many images; in other words, 6bits of data is often
su¢ cient for images to be viewed by humans.
Quantization is performed by some kind of digital comparator, which is an inher-
ently nonlinear electronic device that accepts an analog input and produces one of
two possible output values that depend on whether the analog input is smaller or
larger than some reference signal; if smaller, the output is a value that may be nor-
malized to “0”and if ) or if larger, the output is a “1”. For example, if the reference
of the comparator is set at 0:5 V and if the input is finput = 0:3 V, then the output
is Q f0:3 Vg = 0. If the input voltage is doubled finput = 0:6 V, then the output is
Q f0:6 Vg = 1. Note that this behavior clearly does not satisfy the requirement for a
linear operator L, where the output is doubled if the input is doubled:
Figure 3.2: Comparator and 2-Bit analog-to-digital converter (ADC). The comparator
may be interpreted as an ampli…er with “in…nite” gain, so that its output is a “high”
voltage if Vin > Vref and a “low” voltage otherwise. The schematic of the ADC con-
sists of 4 comparators whose reference voltages are determined by the voltage divider
with the resistor ladder.
Emax Emin b
E^ [x; y] = fq [x; y] + Emin +
2m 1 2
Usually (of course), E^ [x; y] 6= E [x; y] due to the quantization, i.e., there will be
quantization error. The goal of optimum quantization is to adjust the quantization
scheme to reconstruct the set of image irradiances which most closely approximates
the ensemble of original values. The criterion which de…nes the goodness of …t and the
statistics of the original irradiances will determine the parameters of the quantizer,
e.g., the set of thresholds between the levels.
The quantizer just described is memoryless, i.e., the quantization level for a pixel
is computed independently that for any other pixel. The schematic of a memoryless
quantizer is shown below. As will be discussed, a quantizer with memory may have
signi…cant advantages.
The di¤erence between the true input irradiance (or brightness) and the corresponding
irradiance corresponding to the computed digital level is the quantization error at that
pixel:
[n x; m y] f [n x; m y] fq [n x; m y] :
Note that the quantization error is bipolar in general, i.e., may take on positive
or negative values. It often is useful to describe the statistical properties of the
quantization error, which will be a function of both the type of quantizer and the
input image. However, if the di¤erence between quantization steps (i.e., the width
of a quantization level) is b, is constant, the quantization error for most images may
be approximated as a uniform distribution with mean value h [n]i = 0 and variance
b2
h( 1 [n])2 i = . The error distribution will be demonstrated for two 1-D 256-sample
12
images. The …rst is a section of a cosine sampled at 256 points and quantized to 64
levels separated by b = 1:
26 CHAPTER 3 REVIEW OF QUANTIZATION
n
Statistics of quantization noise: (a) f [n] = 63 cos 2 1024 where 0 n 255 (one
quarter of a cycle); (b) after quantization by rounding to nearest integer; (c)
quantization error " [n] = f [n] fq [n], showing that 21 " + 12 ; (d) histogram of
256 samples of quantization error, which shows that the error is approximately
uniformly distributed.
The computed mean of the error 1 [n] = f1 [n] Qff1 [n]g is h 1 [n]i = 5:1
1
10 4 and the variance is h 21 [n]i = 0:08 ' 12 . That the distribution of the errors is
approximately uniform is shown by the histogram.
The second image is comprised of 256 samples of Gaussian distributed random
noise in the interval [0,63]. The image is quantized to 64 levels.Again, the error 2 [n]
is uniformly distributed in the interval [ 0:5; +0:5] with mean 4:09 10 2 ' 0 and
1
variance 2 = h 22 [n]i >= 0:09 ' 12 .
3.2 QUANTIZATION ERROR (“NOISE”) 27
Statistics of quantization error for Gaussian distributed random noise: (a) f [n] with
= 27:7; = 11; (b) after quantization by rounding to nearest integer; (c)
quantization error " [n] = f [n] fq [n], showing that 12 " + 12 ; (d) histogram of
256 samples of quantization error, which shows that the error is approximately
uniformly distributed.
The total quantization error is the sum of the quantization error over all pixels in
the image:
XX
= [n x; m y] :
i j
An image with large bipolar error values may thus have a small total error. The
mean-squared error (the average of the squared error) is a better descriptor of the
…delity of the quantization:
2 1 XX 2
= [n x; m y] ;
N i j
28 CHAPTER 3 REVIEW OF QUANTIZATION
W 2
where N is the number pixels in the image. If the irradiance is measured in mm 2;
W 2
will have units of mm 2 , so it is common to evaluate the square root to compute
the root-mean-squared error (RMS), which has the same dimensions as the error (or
as the signal):
s
p
2 =
1 XX 2
RMS Error = [n x; m y]:
N i j
It should be obvious that the RMS error obtained for one image using di¤erent quan-
tizers will depend on the choice used, and that the RMS error from one quantizer will
di¤er for di¤erent images. It should also be obvious that it is desirable to minimize
the RMS error in an image. The brute-force method for minimizing quantization
error is to add more bits to the ADC, which increases the cost of the quantizer and
the memory required to store the image. There also is a limit to the e¤ectiveness of
such an approach, since the output from a quantizer with a very small step size will
be noisy.
2
where the variance of a signal is a measure of the spread of its amplitude about
the mean value:
Z +1 Z +
X0
2 1 2
2
f = [f [x] hf [x]i] dx ! [f [x] hf [x]i]2 dx
1 X0 X0
2
Thus a large SNR means that there is a larger variation of the signal amplitude
than of the noise amplitude. The de…nition of SNR as the ratio of variances may
have a large range of values –easily several orders of magnitude –and the numerical
values may become unwieldy. The range of SNR may be compressed by expressing it
on a logarithmic scale as a dimensionless quantity called a bel:
2 2
f f f
SN R = log10 2
= log10 = 2 log10 [bels]
n n n
This de…nition of SNR is even more commonly expressed in units of tenths of a bel,
or decibels, so that the integer value is more precise:
2
f f
SN R = 10 log10 2
= 20 log10 [decibels]
n n
3.2 QUANTIZATION ERROR (“NOISE”) 29
Under this de…nition, the SNR is 10 dB if the signal variance is ten times larger than
the noise variance and 20 dB if the standard deviation is ten times larger than that
of the noise.
The variances obviously depend on the independent statistics (speci…cally on the
histograms) of the signal and noise. The variances do not depend on the “arrange-
ment”of the gray levels (i.e., the numerical “order”or “pictorial”appearance of the
pixel gray values) in the image. Since the noise often is determined by the mea-
surement equipment, a single measurement of the noise variance often is used for
many signal amplitudes. However, the signal variance must be measured each time.
Consider a few examples of common 1-D signals.
x
f [x] = A0 cos 2 =) hf [x]i = 0
X0
Z +
X0 Z +
X0
2
2 1 2
2 1 2 x
f = [f [x] hf [x]i] dx = A0 cos 2 dx
X0 X0
2
X0 X0
2
X0
Z X
+ 20
A20 1 x A20
= 1 + cos 4 dx = (X0 + 0)
X0 X0
2
2 X0 2X0
2 A20
f = for sinusoid with amplitude A0
2
Note that the variance of the sinusoid does not depend on the period (i.e., on the
spatial frequency) or on the initial phase – it is a function of the histogram of the
values in a period and not of the “ordered” values. It also does not depend on any
“bias” (additive constant) in the signal. The standard deviation of the sinusoid is
just the square root of the variance:
A0
f = p for sinusoid with amplitude A0
2
30 CHAPTER 3 REVIEW OF QUANTIZATION
1 X0 X0
= A20 + A20 = A20
X0 2 2
2
=) f = A20 for square wave with amplitude A0
=) f = A0 for square wave with amplitude A0
Note that:
( f )square wave, amplitude A0 >( f )sinusoid, amplitude A0
which makes intuitive sense, because the amplitude of the square wave is often more
“distant”from its mean than the sinusoid is.
A20
Sinusoid with amplitude A0 =) 2
f = ; ( f )2 = (2A0 )2 = 4A20 = 8 2
f
2
Square wave with amplitude A0 =) 2
f = A20 ; ( f )2 = (2A0 )2 = 4A20 = 4 2
f
3.2 QUANTIZATION ERROR (“NOISE”) 31
Figure 3.3: One exemplar and the histogram of 8192 samples from the Gaussian
distribution
" with mean# value = 4 and standard deviation = 2: p [n] =
2
1 n 4
p exp
2 2
For Gaussian noise with variance 2 = 1 and mean , the dynamic range of the noise
technically is in…nite, but since few amplitudes exist that are outside of the interval
of four standard deviations measured from the mean. This means that the extrema
of the Gaussian distribution may be approximated by fmax = + 4 , fmin = 4 ,
2
leading to f = 8 . The estimate of the variance of the signal is then ( f ) = 64 f2 ,
which is (obviously) 64 times larger than the actual variance. Because this estimate
of the signal variance is too large, the estimates of the SNR thus obtained will be too
optimistic.
Often, the signal and noise of images are measured by photoelectric detectors as
di¤erences in electrical potential in volts; the signal dynamic range is Vf = Vmax Vmin ,
the average noise voltage is Vn , and the signal-to-noise ratio is:
Vf2 Vf
SN R = 10 log10 = 20 log10 [dB]
Vn2 V
As an aside, we mention that the signal amplitude (or level) of analog electrical signals
often is described in terms of dB measured relative to some …xed reference signal. If
the reference level is V = 1 V (regardless of the impedance), then the signal level is
measured in units of “dBV:”
“dBmV:”
!
2
Vf
level = 10 log10 dBV = 60 log10 (Vf ) dBmV
10 3 V
We now …nally get to the goal of this section: to determine the signal-to-noise ratio
of quantization of a signal. Clearly the quantized signal exhibits an error from the
original analog signal, which leads to the quantity of “noise” and thus a measure of
SNR. . Though in a strict sense the input signal and the type of quantizer determine
the probability density function of the quantization error, it usually is appropriate to
assume that the error due to quantization is uniformly distributed, i.e., the probability
density function is a rectangle. In the case of an m-bit uniform quantizer (2m gray
levels) where the levels are spaced by intervals of width b0 over the full analog dynamic
range of the signal, the error due to quantization will be (approximately) uniformly
distributed over this interval b0 ; this will be demonstrated in the following examples.
If the nonlinearity of the quantizer is rounding, the mean value of the error is 0; if
truncation to the next lower integer, the mean value is b20 . Any book on probability
and statistics likely will demonstrate that the variance and standard deviation of
uniformly distributed noise over a range b0 are:
2 b20
n =
12
r
b20 b0
n = =p
12 12
This also may be derived quite easily by evaluating the terms in the expression for
the variance:
2
n = n
2
hni2
where the noise function is
" #
1 n b20
pn = RECT
b0 b0
b0
This means that the mean value hni = and the mean value of n2 is:
2
Z Z " #
2
+1
1 +1 2 n b20
n = n2 p [n] dn = n RECT dn
1 b0 1 b0
Z b0 n=b0
1 1 n3 1 b30 b2
= n2 dn = = = 0
b0 0 b0 3 n=0 b0 3 3
3.2 QUANTIZATION ERROR (“NOISE”) 33
For an m-bit quantizer and a signal with with maximum and minimum amplitudes
fmax and fmin (and range f = fmax fmin ), the width b0 of a quantization level (the
step size) has the value:
fmax fmin f
b0 = = ( f) 2 m
2m 2m
If we can assume that the quantization noise is uniformly distributed, then the vari-
ance of the quantization noise is well de…ned:
2
b2 1 f 1
2
n = 0 = = ( f )2 12 22m
12 12 2m
The SNR is the ratio of the variance of the signal to that of the noise due to quanti-
zation:
2 2m
f 2 12 2
= f
2
n ( f )2
This may be expressed on a logarithmic scale to yield the (sort of) simple expression:
SN R = 10 log10 2
f 12 22m 10 log10 ( f )2
= 10 log10 2
f + 10 log10 [12] + 20 m log10 [2] 10 log10 ( f )2
= 10 log10 2
f + 10 1:079 + 20 m 0:301 10 log10 ( f )2
2
f
= 6:02 m + 10:8 + 10 log10 [dB]
( f )2
The third term obviously depends on the parameters of both the signal and the quan-
tizer. This equation demonstrates one result immediately – that the SNR of quan-
tization increases by ' 6 dB for every bit added to the quantizer (again, assuming
uniform distribution of the noise). If using the (poor) estimate that f2 = ( f )2 , then
the third term evaluates to zero and the approximate SNR is:
SN R for quantization to m bits = 6:02 m + 10:8 + 10 log10 [1]) = 6:02 m + 10:8 [dB]
The statistics (and thus the variance) may be approximated for many types of
signals (e.g., music, speech, realistic images) as resulting from a random process.
The histograms of these signals usually are peaked at or near the mean value and
the probability of a gray level decreases for values away from the mean; the signal
34 CHAPTER 3 REVIEW OF QUANTIZATION
1
SN R = 6:02 m + 10:8 + 10 log10
64
= 6:02 m + 10:8 + 10 ( 1:806)
= 6:02 m 7:26 [dB]
This equation may be applied to demonstrate that the SNR of a noise-free analog
signal after quantizing to 8 bits is = 41 dB. The SNR of the same signal quantized
to 16 bits (common in CD players) is approximately 89 dB. The best SNR that can
be obtained from analog recording (such as on magnetic tape) is about 65 dB, which
is equivalent to that from a signal digitized to 12 bits per sample or 4096 levels.
The ‡ip side of this problem is to determine the e¤ective number of quantization
bits after digitizing a noisy analog signal. This problem was investigated by Shannon
in 1948. The analog signal is partly characterized by its bandwidth [Hz], which
is the analog analogue of the concept of digital data rate [bits per second]. The
bandwidth is the width of the region of support of the signal spectrum (its Fourier
transform).
3.3 QUANTIZATION TO FEW BITS 35
2. If most sign…cant four bits of current pixel evaluate to 1111, then set the new
sum to those four bits + 0000, otherwise set new sum with the four most
signi…cant bits plus the 4 least sign…cant bits of the old sum.
Example
Pixel Index Gray Binary Code Sum of 8-bit binary and 4-bit error 4-bit IGS Gray
A simple method for quantizing with memory that generally results in reduced
total error without a priori knowledge of the statistics of the input image and without
adding much additional complexity of computation was introduced by Floyd and
Steinberg (SID 36, 1976) as a means to simulate gray level images on binary image
displays and is known as error di¤usion. It is easily adapted to multilevel image
quantization. As indicated by the name, in error di¤usion the quantization error is
from one pixel is used to in the computation of the levels of succeeding pixels. In
its simplest form, all quantization error at one pixel is added to the gray level of the
next pixel before quantization.
In the 1-D case, the quantization level at sample location x is the gray level of the
sample minus the error [x 1] at the preceding pixel:
Usually, the error is reset to zero at the beginning of each line. You can see that
this is simple to implement and the results are often very useful. Several years back,
John Knapp (CIS undergraduate and graduate student) used 1-D error di¤usion to
improve the reconstructions of computer-generated holograms for several di¤erent
applications and the results were often excellent (§23.4 in my book Fourier Methods
in Imaging).
In the 2-D case, it is possible (and often desirable) to divide and apply the resulting
quantization error weight among di¤erent as-yet unquantized pixels. The “standard”
Floyd-Steinberg algorithm quantizes the N N image in a raster from the upper
left corner (sequence of pixels: …rst row from left to right, then second row from left
to right, etc. to the bottom line of pixels). At each pixel, the quantization error is
7
evaluated and divided among four pixels yet to be quantized: 16 of this result is added
5 3
to the next pixel in line, 16 to the pixel below, 16 to the pixel below and “forward”,
3.3 QUANTIZATION TO FEW BITS 37
1
and 16
to the pixel below and “afterward.”A …gure is helpful:
7
16
3 5 1
16 16 16
The end result is an array of bitonal pixels (black and white) where the density of
white pixels is proportional to the gray value. The examples demonstrate the e¤ects
of binary quantization on gray-level images. The images of the ramp demonstrate
that why the binarizer with memory is often called pulse-density modulation. Note
that more …ne detail is preserved in binarized images from the quantizer with memory
(e.g.,the sky in Liberty and the shoulder in Lincoln). This is accomplished by possibly
enhancing the local binarization error.
2-D error-di¤used quantization for three gray-scale images: (a) linear ramp, after
quantizing at the midgray level, after Floyd-Steinberg error di¤usion at the midgray
level; (b) same sequence for "Lincoln"; (c) same sequency for "Liberty." The
error-di¤used images convey more information about the more raplidly varying
structure in the scenes.
38 CHAPTER 3 REVIEW OF QUANTIZATION
Error di¤usion has applications beyond quantization – for example, Eschbach and
Knox have used it to create algorithms for edge enhancement.
A discussion of the use of error di¤usion in ADC was given by Anastassiou (IEEE
Trans. Circuits and Systems, 36, 1175, 1989).