Art of Image Processing Trailer
Art of Image Processing Trailer
i i
The Art of
Image Processing
with Java
i i
i i
i i
i i
i i
i i
i i
i i
The Art of
Image Processing
with Java
Kenny A. Hunt
A K Peters, Ltd.
Natick, Massachusetts
i i
i i
i i
i i
A K Peters, Ltd.
5 Commonwealth Road, Suite 2C
Natick, MA 01760
www.akpeters.com
All rights reserved. No part of the material protected by this copyright notice
may be reproduced or utilized in any form, electronic or mechanical, including
photocopying, recording, or by any information storage and retrieval system,
without written permission from the copyright owner.
Hunt, Kenny A.
The art of image processing with Java / Kenny A. Hunt.
p. cm.
Includes bibliographical references and index.
ISBN 978-1-56881-717-0 (alk. paper)
1. Image processingDigital techniques. 2. Java (Computer program language)
I. Title.
TA1637.H87 2010
621.36702855133dc22
2010027302
Printed in India
12 11 10 09 08 10 9 8 7 6 5 4 3 2 1
i i
i i
i i
i i
Contents
1 Introduction 1
1.1 What Is Digital Image Processing? . . . . . . . . . . . . . . . 1
1.2 Why Digital Image Processing? . . . . . . . . . . . . . . . . . 5
3 Digital Images 25
3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.2 Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.3 Digital Images . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.4 Acquisition . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.5 Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
3.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
i i
i i
i i
i i
vi CONTENTS
i i
i i
i i
i i
CONTENTS vii
B Scanners 335
References 339
References 339
Index 341
i i
i i
i i
i i
i i
i i
i i
i i
Introduction
1
1.1 What Is Digital Image Processing?
We must begin our journey by taking issue with the philosophical adage that a
picture is worth a thousand words. It is my belief that a picture cannot begin to
convey the depth of human experience and wisdom embedded in the words of
Shakespeare, Dostoevsky, Dante, or Moses. A picture cannot convey with due
precision the mathematical underpinnings of the discoveries of Galileo or Pas-
cal nor can a picture give expression to the philosophy of Augustine, Plato, or
Edwards. Nonetheless, while pictures do not carry the precision of written lan-
guage, they do contain a wealth of information and have been used throughout
the centuries as an important and useful means of communication. An image is
a picture representing visual information. A digital image is an image that can be
stored in digital form.
Prior to the advent of computation, images were rendered on papyrus, paper,
film, or canvas using ink or paint or photosensitive chemicals. The non-digital
images are prone to fading and hence suffer loss of image quality due to exposure
to light or temperature extremes. Also, since non-digital images are fixed in
some physical medium it is not possible to precisely copy a non-digital image.
Throughout the annals of art history, forgers have attempted to copy paintings of
well-known masters but usually fail due to their inability to precisely duplicate
either a style or an original work. Han van Meegeren is one of the best known
art forgers of the 20th century. His technique so closely mimicked the style and
colors of the art masters that he was able to deceive even the most expert art
critics of his time. His most famous forgery, The Disciples at Emmaus, was created
in 1936 and was purportedly created by the well-known Dutch artist Johannes
Vermeer. His work was finally exposed as fraudulent, however, at least in part
by a chemical analysis of the paint, which showed traces of a plastic compound
that was not manufactured until the 20th century!
Digital images, however, are pictures that are stored in digital form and that
are viewable on some computing system. Since digital images are stored as bi-
nary data, the digital image never fades or degrades over time and the only way
i i
i i
i i
i i
2 1. Introduction
to destroy a digital image is to delete or corrupt the file itself. In addition, a dig-
ital image can be transmitted across the globe in seconds and can be efficiently
and precisely copied without any loss of quality.
Digital image processing is a field of study that seeks to analyze, process, or
enhance a digital image to achieve some desired outcome. More formally, digital
image processing can be defined as the study of techniques for transforming a
digital image into another (improved) digital image or for analyzing a digital
image to obtain specific information about the image.
From the cradle to the grave we are accustomed to viewing life through dig-
ital images. A parents first portrait of their child is often taken before they are
even born through the use of sophisticated ultrasound imaging technology. As
the child grows, the parents capture developmental milestones using palm-sized
digital video cameras. Portraits are sent over email to relatives and friends and
short video clips are posted on the familys website. When the child breaks an
arm playing soccer, the emergency-room physician orders an x-ray image and
transmits it over the Internet to a specialist hundreds of miles away for immedi-
ate advice. During his lifetime the child will watch television images that have
been digitally transmitted to the dish on top of his house, view weather satellite
images on the Internet to determine whether or not to travel, and see images of
war where smart bombs find their target by seeing the enemy.
Computer graphics is a closely related field but has a different goal than im-
age processing. While the primary goal of computer graphics is the efficient
generation of digital images, the input to a graphics system is generally a geo-
metric model specifying the shape, texture, and color of all objects in the virtual
scene. Image processing, by contrast, begins with a digital image as input and
generates, typically, a digital image as output.
Computer vision, or machine vision, is another increasingly important rel-
ative of image processing where an input image is analyzed in order to deter-
mine its content. The primary goal of computer vision systems is the inverse of
i i
i i
i i
i i
i i
i i
i i
i i
4 1. Introduction
i i
i i
i i
i i
These five stages serve as a general outline for the remainder of this text. The
image processing topics associated with each stage of the processing pipeline will
be discussed with an emphasis on the processing stage which lies at the heart of
image processing. By contrast, little coverage will be allocated to transmission
issues in particular.
1.2.1 Medicine
Digital imaging is beginning to supplant film within the medical field. Computed
tomography (CT) is a noninvasive imaging technique used to diagnose various
ailments such as cancers, trauma, and musculoskeletal disorders. Magnetic reso-
nance imaging (MRI) is a similarly noninvasive method for imaging the internal
structure and function of the body. MRI scans are more amenable to diagnosing
neurological and cardiovascular function than CT scans due to their greater con-
trast among soft tissue volumes. Figure 1.4 gives an example of both MRI and
CT images where the MRI highlights contrast in the internal soft-tissue organs
of a human pelvis while the CT image captures the internal skeletal structure of
a human skull.
i i
i i
i i
i i
6 1. Introduction
1.2.2 Biology
Biology is a natural science that studies living organisms and how they inter-
act with the environment. Biological research covers a vast array of specialized
subdisciplines such as botany, zoology, cell biology, microbiology, and biochem-
istry. Each of these disciplines relies to some degree on sophisticated computing
systems to acquire and analyze large amounts of image-based data. These mea-
surements ultimately provide information required for tasks such as deciphering
complex cellular processes and identifying the structure and behavior of DNA.
Since image-based measurement is becoming increasingly vital to biological
research, biologists must have basic knowledge in image processing to correctly
interpret and process their results. Part (a) of Figure 1.5 shows a scanning elec-
tron microscope (SEM) image of a rust mite where the length of the mite is on
the order of 60 m. Part (b) shows the structure of the eye of a fruit fly where
each spherical sensor is on the order of 10 m in diameter.
i i
i i
i i
i i
(a) A rust mite (Aceria anthocoptes). (b) The eye of a fruit fly (Drosophilidae).
1.2.3 Biometrics
The security of national, corporate, and individual assets has become a topic
of great importance in the modern global economy as terrorists, con men, and
white-collar criminals pose an ongoing threat to society. When a person boards
an airplane, enters credit card information over the Internet, or attempts to ac-
cess medical records for a hospital patient, it is desirable to verify that the person
actually is who they claim to be. The field of biometrics seeks to verify the iden-
tity of individuals by measuring and analyzing biological characteristics such as
fingerprints, voice patterns, gait, facial appearance, or retinal scans. In most of
these techniques, with the exception of voice recognition, the biological traits are
obtained by the analysis of a digital image.
Biometrics has been used for decades in law enforcement to identify criminals
from fingerprint images. Highly trained experts have traditionally performed fin-
gerprint identification manually by comparing fingerprints of criminal suspects
with fingerprints obtained from a crime scene. Systems are now commonly used
to match fingerprints against large databases of suspects or known criminals.
Specialized hardware is used to first acquire a digital image of an individuals
fingerprint. Software is then used to analyze the image and compare it with a
large database of known fingerprint images. Since the process is automated, it
is possible to quickly search a very large database and quickly obtain accurate
verification.
The use of palm scans is proving increasingly effective in the field of biomet-
rics. A palm scanner is used to acquire an image of the blood flow through the
veins of the hand in a completely non invasive and contact-free fashion. Since the
veins form a complex three-dimensional structure within a persons palm, indi-
viduals can be identified with extremely high accuracy, and forgery is extremely
difficult.
i i
i i
i i
i i
8 1. Introduction
Figure 1.6. Satellite images of the St. Louis flood. (Image courtesy of NASA/Goddard
Space Flight Center Scientific Visualization Studio.)
i i
i i
i i
i i
1.2.5 Robotics
The field of robotics has made astounding progress in recent years. Robots now
appear on the shelves of commercial toy stores, in industrial manufacturing lines,
and in search and rescue missions. At the heart of most intelligent robots is a set
of image processing routines that is able to process images gathered by the robots
eyes and determine how the robots should respond to their visually perceived
environment. A team of robotics experts from the University of Southern Florida
was brought in to assist in the search and rescue mission during the days after the
World Trade Center collapse. These robots were specifically designed to navigate
through dangerous situations looking for signs of life.
i i
i i
i i
i i
10 1. Introduction
1.2.7 Astronomy
Astronomers have long used digital images to study deep space over much of
the electromagnetic spectrum: the Compton Gamma Ray Observatory captures
digital images primarily in the gamma ray spectrum; the Chandra X-Ray Ob-
servatory and the Space Infrared Telescope Facility (also known as the Spitzer
Space Telescope) provide coverage of the x-ray and infrared portions of the spec-
trum, respectively. The most well known telescope covering the visible portion
of the spectrum is the Hubble Space Telescope, which was launched in 1990.
The Hubble Telescope orbits the earth with a reflector-style optics system and a
mirror of 2.4 meters in diameter. The focal length is 57.6 meters and it is able
to take infrared images as well as images in the visible spectrum. Of course the
images are digital since they must be transmitted to ground stations for viewing
and analysis. The Hubble has produced some of the most remarkable images
ever taken of created order.
Figure 1.7 is an image of the Antennae galaxies. These two galaxies are
located in the constellation Corvus and are in the process of collapsing into a
Figure 1.7. Hubble Space Telescope image of the Antennae galaxies. (Image courtesy of
NASA, ESA, and the Hubble Heritage Team.)
i i
i i
i i
i i
single galaxy. These galaxies are approximately 45 million light years away, and
scientists predict that within 400 million years the two galaxies will have merged
to form a single elliptical galaxy.
1.2.8 Conclusion
Ours is an increasingly visual culture and digital imaging is pervasive across
nearly all professions, disciplines, and academic fields of study. The study of
digital image processing will provide a foundation for understanding how best
to acquire digital images, the nature of information contained within a digital
image, and how to best archive and display images for specific purposes or ap-
plications.
Artwork
Figure 1.3. Migrant Mother by Dorothea Lange (18951965). Dorothea Lange
was born in Hoboken, New Jersey in 1895 and devoted herself to portrait pho-
tography at a young age. After apprenticing with a photographer in New York
City, she moved to San Francisco and worked predominantly with the upper
class. After about 13 years she developed the desire to see things from a different
point of view and Lange began shooting among San Franciscos unemployed and
documenting the increasing labor unrest. She was eventually hired by the Farm
Security Administration (FSA) as a photographer and photojournalist. She is
best known for her work with the FSA, which put a human face on the tragedy
of the Great Depression and profoundly influenced the field of photojournalism
in subsequent years. She died on October 11, 1965. Her most famous portrait is
entitled Migrant Mother, which is shown in Figure 1.3. The image is available
from the United States Library of Congresss Prints and Photographs Division
using the digital ID fsa.8b29516.
i i
i i
i i
i i
i i
i i
i i
i i
h(i) = ni i 0, 1, . . . , 2N (5.10)
Histograms are typically normalized such that the histogram values sum to 1.
In Equation (5.10) the histogram is not normalized since the sum of the his-
togram values is W H. The normalized histogram is given in Equation (5.11),
where h(i) represents the probability that a randomly selected sample of the im-
age that will have a value of i:
i i
i i
i i
i i
(a) (b)
Figure 5.8. An example histogram: (a) an 8-bit grayscale image and (b) its histogram.
to 80, while relatively few of the images samples are brighter than 128. The
histogram for this example is indicative of an underexposed imageone that
may be improved through histogram equalization.
Histogram equalization is a way of improving the local contrast of an image
without altering the global contrast to a significant degree. This method is es-
pecially useful in images having large regions of similar tone such as an image
with a very light background and dark foreground. Histogram equalization can
expose hidden details in an image by stretching out the contrast of local regions
and hence making the differences in the region more pronounced and visible.
Equalization is a nonlinear point processing technique that attempts to map
the input samples to output samples in such a way that there are equal amounts
of each sample in the output. Since equalization is a point processing technique
it is typically implemented through the use of a lookup table. For a source im-
age, equalization computes the histogram of the source and then constructs a
discrete cumulative distribution function (CDF) which is used as the lookup ta-
ble. Given an N-bit image having histogram h, the normalized CDF C is defined
in Equation (5.12):
j
X
Cj = hi , j {0, 1, . . . , 255} . (5.12)
i=0
i i
i i
i i
i i
i hi Ci 7Ci i hi
0 1/16 1/16 0 0 1/16
1 3/16 4/16 2 1 0/16
0 1 3 4 0 2 5 7
2 4/16 8/16 4 2 3/16
1 2 2 3 2 4 4 5
3 4/16 12/16 5 3 0/16
1 3 4 4 2 5 7 7
4 3/16 15/16 7 4 4/16
3 2 5 2 5 4 7 4
5 1/16 16/16 7 5 4/16
6 0/16 16/16 7 6 0/16
7 0/16 16/16 7 7 4/16
(a) (b) (c) (d)
Figure 5.9. Numerical example of histogram equalization: (a) a 3-bit image, (b) normal-
ized histogram and CDF, (c) the equalized image, and (d) histogram of the result.
i i
i i
i i
i i
6000
Number of Occurrences
5000
4000
3000
2000
1000
0
0 50 100 150 200 250
Sample Value
850
800
750
700
650
600
550
0 50 100 150 200 250
Sample Value
i i
i i
i i
i i
Number of Occurrences
3000
2500
2000
1500
1000
500
0
0 50 100 150 200 250
Sample Value
900
Number of Occurrences
800
700
600
500
400
0 50 100 150 200 250
Sample Value
i i
i i
i i
i i
i i
i i
i i
i i
1 p u b l i c c l a s s Histogram {
2 private int [ ] counts ;
3 p r i v a t e i n t t o t a l S a m p l e s , m axP ossi bleS ampl eVa lue ;
4
5 p u b l i c Histogram ( B u f f e r e d I m a g e s r c , i n t band ) {
6 ma xPos sibl eSam ple Valu e = getMaxSampleValue ( s r c , band ) ;
7 c o u n t s = new i n t [ max Poss ible Sam pleV alue + 1 ] ;
8 t o t a l S a m p l e s = s r c . getWidth ( ) s r c . g e t H e i g h t ( ) ;
9
10 f o r ( L o c a t i o n p t : new R a s t e r S c a n n e r ( s r c , f a l s e ) ) {
11 i n t sample = s r c . g e t R a s t e r ( ) . g e t S a m p l e ( p t . c o l , p t . row , band ) ;
12 c o u n t s [ sample ]++;
13 }
14 }
15
16 p u b l i c i n t getNumberOfBins ( ) {
17 return counts . length ;
18 }
19
20 public i n t getValue ( i n t index ){
21 return counts [ index ] ;
22 }
23
24 public i n t [ ] getCounts ( ) {
25 i n t [ ] r e s u l t = new i n t [ c o u n t s . l e n g t h ] ;
26 System . a r r a y c o p y ( c o u n t s , 0 , r e s u l t , 0 , c o u n t s . l e n g t h ) ;
27 return r e s u l t ;
28 }
29
30 p u b l i c double [ ] getCDF ( ) {
31 double [ ] c d f = g e t N o r m a l i z e d H i s t o g r a m ( ) ;
32 f o r ( i n t i =1; i<c d f . l e n g t h ; i ++){
33 c d f [ i ] = c d f [ i 1] + c d f [ i ] ;
34 }
35 return cdf ;
36 }
37
38 p u b l i c double [ ] g e t N o r m a l i z e d H i s t o g r a m ( ) {
39 double [ ] r e s u l t = new double [ c o u n t s . l e n g t h ] ;
40 f o r ( i n t i =0; i<c o u n t s . l e n g t h ; i ++){
41 r e s u l t [ i ] = c o u n t s [ i ] / ( double ) t o t a l S a m p l e s ;
42 }
43 return r e s u l t ;
44 }
45
46 p r i v a t e i n t getMaxSampleValue ( B u f f e r e d I m a g e s r c , i n t band ) {
47 r e t u r n ( i n t ) Math . pow ( 2 , s r c . getSampleModel ( ) . g e t S a m p l e S i z e ( band ) ) 1 ;
48 }
49 }
i i
i i
i i
i i
i i
i i
i i
i i
Figure 5.13. The color distribution of two source images as given by their 12 12 12 RGB
color histograms.
i i
i i
i i
i i
Index
341
i i
i i
i i
i i
342 Index
i i
i i
i i
i i
Index 343
cornea, 18 frequency, 42
fovea, 18 quanitization, 44
iris, 18 resolution, 42
optic nerve, 19 sampling, 44
perimetric angle, 18 image arithmetic, 107
pupil, 18 image blending, 107
retina, 18 image compression, 255
rods and cones, 18 image frequency, 217
visual axis, 18 ImageComponent (pixeljelly.gui), 76
ImageDecoder (pixeljelly.io), 266
FalseColorOp (pixeljelly.ops), 98 ImageEncoder (pixeljelly.io), 264
fast Fourier transform, 247 ImageIO (javax.imageio), 66
feature, 313 ImagePadder (pixeljelly.utilities), 129
feature vector, 313 ImageTiler (imaging.scanners), 324
FFT, 247 immediate mode, 62
flood filling, 300 indexed image, 60
Floyd-Steinberg dithering, 208 interpixel redundancy, 255
FloydSteinbergDitheringOp (pixeljelly.ops), Interpolant (imaging.utilities), 186
212 interpolation, 180
forward mapping, 178 InverseMapper (imaging.utilities), 187
frequency, 42 invertibility, 221
InvertOp (pixeljelly.ops), 73
gamma correction, 92
GammaOp (pixeljelly.ops), 95 Jarvis-Judice-Ninke dithering, 209
Gaussian filter, 242 Java Advanced Imaging (JAI), 329
geometric operations, 173 Java Media suite, 329
GeometricTransformOp (imaging.ops), 188 JPEG, 280
GIF, 284
gradient, 145 kernel, 124
grayscale image, 37 Kernel (java.awt.image), 134
Kernel2D (pixeljelly.utilities), 135
halftoning, 198 key element, 124
analog, 198
digital, 198 least significant bit embedding, 287
high dynamic range imaging, 21 lens, 15
high pass filter, 242 focal length, 15
histogram, 99 magnification factor, 15
color, 106 thin lens equation, 15
Histogram (pixeljelly.features), 104 light, 13
histogram equalization, 99 amplitude, 13
homogeneous coordinate, 174 frequency, 13
homogeneous transformation matrix, 174 wavelength, 13
LinearArrayDigitalImage (imaging), 57
ideal filter, 239 Location (pixeljelly.scanners), 71
image logical operators, 113
acquisition, 43 lookup tables, 90
continuous tone, 44 LookupOp (java.awt.image), 91
i i
i i
i i
i i
344 Index
i i
i i
i i
i i
Index 345
i i
i i