The Essential Guide to Image Processing- P2 pot - Pdf 15

2.2 LabVIEW For Image Processing 27
the block diagram. The results of the operation are then passed back to the front
panel indicators. A typical block diagram is shown in Fig. 2.1(b). Within the block
diagram, you have access to a full-featured graphical programming language that
includes all the standard features of a general-purpose programming environment,
such as data structures, looping structures, event handling, and object-oriented
programming.

Icon and connector pane—identifies the interface to the VI so that you can use
the VI in another VI. A VI within another VI is called a sub-VI. Sub-VIs are
analogous to subroutines in conventional programming languages. A sub-VI is a
virtual instr ument and can be run as a program, with the front panel serving as a
user interface, or, when dropped as a node onto the block diagram, the front panel
defines the inputs and outputs for the given node through the connector pane.
This allows you to easily test each sub-VI before being embedded as a subroutine
into a larger program.
LabVIEW also includes debugging tools that allow you to watch data move through
a program and see precisely which data passes from one function to another along the
wires, a process known as execution highlighting. This differs from text-based languages,
which require you to step from function to function to trace your program execution.
An excellent introduction to LabVIEW is provided in [4, 5].
2.2.2 Image Processing and Machine Vision in LabVIEW
LabVIEW is widely used for programming scientific imaging and machine vision appli-
cations because engineers and scientists find that they can accomplish more in a shorter
period of time by working with flowcharts and block diagrams instead of text-based
function calls. The NI Vision Development Module [6] is a software package for engineers
and scientists who are developing machine vision and scientific imaging applications.
The development module includes NI Vision for LabVIEW—a library of over 400 func-
tions for image processing and machine vision and NI Vision Assistant—an interactive
environment for quick prototyping of vision applications without programming. The
development module also includes NI Vision Acquisition—software with support for

image, read and set values along a row or column in an image, and fill the pixels in
an image with a particular value;
– overlay figures,text, and bitmaps onto an image without destroying the image data.
Use these VIs to overlay the results of your inspection application onto the images
you inspected;
– spatially calibrate an image. Spatial calibration converts pixel coordinates to real-
world coordinates while compensating for potential perspective er rors or nonlinear
distortions in your imaging system;
– manipulate the colors andcolorplanes of an image. UsetheseVIs to extract different
color planes from an image, replace the planes of a color image with new data,
convert a color image into a 2D array and back, read and set pixel values in a color
image, and convert pixel values from one color space to another.
Image Processing VIs Allow you to analyze, filter, and process images according to
the needs of your application. This category includes VIs for analysis, grayscale and
2.2 LabVIEW For Image Processing 29
binary image processing, color processing, frequency processing, filtering, morphology,
and operations.
You can use these VIs to:
– transform images using predefined or custom lookup tables, change the contrast
information in an image, invert the values in an image, and segment the image;
– filter images to enhance the information in the image. Use these VIs to smooth
your image, remove noise, and find edges in the image. You can use a predefined
filter kernel or create custom filter kernels;
– perform basic mor phological operations, such as dilation and erosion, on grayscale
and binary images. Other VIs improve the quality of binary images by filling holes
in particles, removing particles that touch the border of an image, removing noisy
particles, and removing unwanted particles based on different characteristics of
the particle;
– compute the histogram information and grayscale statistics of an image, retrieve
pixel information and statistics along any 1D profile in an image, and detect and

– compare images to a golden template reference image;
– classify unknown objects by comparing significant features to a set of features that
conceptually represent classes of known objects;
– read text and/or characters in an image;
– develop applications that require reading from seven-segment displays, meters or
gauges, or 1D barcodes.
2.2.2.2 NI Vision Assistant
NIVisionAssistant isa tool for prototyping and testing image processing applications.You
can create custom algorithms with the Vision Assistant scripting feature, which records
every step of your processing algorithm. After completing the algorithm, you can test it
on other images to check its reliability. Vision Assistant uses the NI Vision library but can
be used independently of LabVIEW. In addition to being a tool for prototyping vision
systems, you can use Vision Assistant to learn how different image processing functions
perform.
The Vision Assistant interface makes prototyping your application easy and efficient
because of features such as a reference window that displays your original image, a script
window that stores your image processing steps, and a processing window that reflects
changes to your images as you apply new parameters (Fig. 2.2). The result of prototyping
an application in Vision Assistant is usually a script of exactly which steps are necessary
to properly analyze the image. For example, as shown in Fig. 2.2, the prototype of bracket
inspection application to determine if it meets specifications has basically five steps: find
the hole at one end of the bracket using pattern matching, find the hole at the other
end of the bracket using pattern matching, find the center of the bracket using edge
detection, and measure the distance and angle between the holes from the center of the
bracket.
Once you have developed a script that correctly analyzes your images, you can use
Vision Assistant to tell you the time it takes to run the script. This information is extremely
valuable if your inspection has to finish in a certain amount of time. As shown in Fig. 2.3,
the bracket inspection takes 10.58 ms to complete.
After prototyping and testing, Vision Assistant automatically generates a block

involved and difficult to interpret, it is nevertheless very easy to visually appreciate
the effects and artifacts int roduced by these processes using the VIs provided in
the SIVA galler y. Figure 2.4, for example, illustrates the “false contouring” effect
of grayscale quantization. While discussing the process of sampling any signal,
students are introduced to the importance of “Nyquist sampling” and warned of
“aliasing”or “false frequency” artifacts introduced by this process. The VI shown in
2.3 Examples from the SIVA Image Processing Demos 33
TABLE 2.1 A list of image and video processing demos available in the SIVA gallery.
Basics of Image Processing: Nonlinear Filtering:
Image quantization Median filtering
Image sampling Gray level morphological filters
Image histogram Trimmed mean filters
Peak and valley detection
Binary Image Processing: Homomorphic filters
Image thresholding
Image complementation Digital Image Coding & Compression:
Binary morphological filters Block truncation image coding
Image skeletonization Entropy reduction via DPCM
JPEG coding
Linear Point Operations:
Full-scale contrast stretch Edge Detection:
Histogram shaping Gradient-based edge detection
Image differencing Laplacian-of-Gaussian
Image interpolation Canny edge detection
Double thresholding
Discrete Fourier Analysis: Contour thresholding
Digital 2D sinusoids Anisotropic diffusion
Discrete Fourier transform (DFT)
DFTs of important 2D functions Digital Video Processing:
Masked DFTs Motion compensation

operations is shown in Fig. 2.6.
■ Linear Point Operations and their Effects on Histograms: Irrespective of their
familiarity with the theory of DIP, most computer and digital camera users are
familiar, i f not proficient, with some form of an image editing software, such as
Adobe Photoshop, Gimp, Picasa, or iPhoto. One of the frequently p erformed oper-
ations (on-camera or using software packages) is that of changing the brightness
and/or contrast of an underexposed or overexposed photograph. To illustrate how
these operations affect the histogram of the image, a VI in SIVA provides the
user with controls to perform linear point operations, such as adding an offset,
2.3 Examples from the SIVA Image Processing Demos 35
(a) (b)
(c) (d) (e)
FIGURE 2.6
Binary morphological operations. (a) Front panel; (b) Original image; (c) Erosion using X-shaped
window; (d) CLOS operation using square window; (e) Median (majority) operation using square
window.
scaling the pixel values by scalar multiplication, and performing full-scale contrast
stretch. Figure 2.7 shows a simple example where the histogram of the input image
is either shifted to the right (increasing brightness), compressed while retaining
shape, flipped to create an image negative, or stretched to fill the range (corres-
ponding to full-scale contrast stretch). Advanced VIs allow the user to change the
shape of the input histogram—an operation that is useful in cases where full-scale
contrast stretch fails.
■ Discrete Fourier Transform: Most of introductory DIP is based on the theory
of linear systems. Therefore, a lucid understanding of frequency analysis tech-
niques such as the Discrete Fourier Transform (DFT) is important to appreciate
more advanced topics such as image filtering and spectral theory. SIVA has many
VIs that provide an intuitive understanding of the DFT by first introducing
the concept of spatial frequency using images of 2D digital sinusoidal gratings.
The DFT VI can be used to compute and display the magnitude and the phase of

c
)(
d
)(
e
)
(a) (b)
FIGURE 2.8
Directionality of the Fourier Transform. (a) Front panel; (b) Original “Cameraman;” (c) DFT
magnitude; (d) Masked DFT magnitude; (e) Reconstructed image.
fundamental ideas of image compression, such as the ability to reduce the entropy
of an image using pulse code modulation. The gallery also contains a VI to illustrate
block truncation coding (BTC)—a very simple yet powerful image compression
scheme. As shown in the front panel in Fig. 2.10, the user can select the number of
bits, B1, used to represent the mean of each block in BTC and the number of bits,
B2, for the block variance. The compression ratio is computed and displayed on
the front panel in the CR indicator in Fig. 2.10.
■ Hough Transform: The Hough transform is useful for detecting straight lines in
images. The transform operates on the edge map of an image. It uses an “accu-
mulator” matrix to keep a count of the number of pixels that lie on a s traight line
of a certain parametric form, say, y ϭ mx ϩ c, where (x,y) are the coordinates of
an edge location, m is the slope of the line, and c is the y-intercept. (In practice,
a polar form of the straight line is used). In the above example, the accumulator
matrix is 2D, with the two dimensions being the slope and the intercept. Each entry
in the matrix corresponds to the number of pixels in the edge map that satisfy that
particular equation of the line. The slope and intercept corresponding to the largest
38 CHAPTER 2 The SIVA Image Processing Demos
(c) (d) (e)
(a) (b)
FIGURE 2.9

State University, USA.
■ VcDemo [10]—A Microsoft Windows-based interactive video and image com-
pression tool from Delft University of Technology, The Netherlands.
Since its release in November 2002, the SIVA demonstration gallery has been gaining
in popularity and is currently being widely used by instructors in many educational
institutions over the world for teaching their signal, image and video processing courses,
40 CHAPTER 2 The SIVA Image Processing Demos
(a)
(b) (c) (d)
FIGURE 2.11
Hough transform. (a) Front panel; (b) original “Tower” image; (c) edge map; (d) lines detected
by Hough Transform.
and by many individuals inindustry for testing theirimage processing algorithms. To date,
there are over 450 institutional users from 54 countries using SIVA. As mentioned earlier,
the entire image processing gallery of SIVA is included in the CD that accompanies this
book as a stand-alone version that does not need the user to own a copy of LabVIEW. All
VIs may also be downloaded directly for free from the Web site mentioned in [2].Wehope
that the intuition provided by the demos will make the reader’s experience with image
processing more enjoyable. Perhaps, the reader’s newly found image processing lingo will
compel them to mention how they “Designed a pseudo-inverse filter for deblurring” in
lieu of “I photoshopped this image to make it sharp.”
ACKNOWLEDGMENTS
Most of the image processing demos in the SIVA g allery were developed by National
Instruments engineer and LIVE student George Panayi as a part of his M.S. Thesis [11].
References 41
The demos were upgraded to be compatible with LabVIEW 7.0 by National Instrument
engineer and LIVE student Frank Baumgartner,who also implemented several video pro-
cessing demos. The authors of this chapter would also like to thank National Instruments
engineers Nate Holmes, Matthew Slaughter, Carleton Heard, and Nathan McKimpson
for their invaluable help in upgrading the demos to be compatible with the latest version

The University of Texas at Austin
3.1 INTRODUCTION
This chapter, and the two that follow, describe the most commonly used and most
basic tools for digital image processing. For many simple image analysis tasks, such as
contrast enhancement, noise removal, object location, and frequency analysis, much of
the necessary collection of instruments can be found in Chapters 3–5. Moreover, these
chapters supply the basic groundwork that is needed for the more extensive developments
that are given in the subsequent chapters of the Guide.
In the current chapter, we study basic gray level digital image processing operations.
The types of oper ations studied fall into three classes.
Thefirstarepoint operations, or image processing operations, that are applied to
individual pixels only. Thus, interactions and dependencies between neighboring pixels
are not considered, nor are operations that consider multiple pixels simultaneously to
determine an output. Since spatial information, such as a pixel’s location and the values
of its neighbors, are not considered, point operations are defined as functions of pixel
intensity only. The basic tool for understanding, analyzing, and designing image point
operations is the image histogram, which will be introduced below.
The second class includes arithmetic operations between images of the same spatial
dimensions. These are also point operations in the sense that spatial information is
not considered, although information is shared between images on a pointwise basis.
Generally, these have special purposes, e.g., for noise reduction and change or motion
detection.
The third class of operations are geometric image operations. These are complementary
to point operations in the sense that they are not defined as functions of image intensity.
Instead, they are functions of spatial position only. Operations of this type change the
appearance of images by changing the coordinates of the intensities. This can be as simple
as image translation or rotation, or may include more complex operations that distort or
bend an image, or “morph” a video sequence. Since our goal, however, is to concentrate
43
44 CHAPTER 3 Basic Gray Level Image Processing

other operations as well) is the image histogram. The histogram H
f
of the digital image
f is a plot or graph of the frequency of occurrence of each gray level in f .Hence,H
f
is
a one-dimensional function with domain {0, ,K Ϫ 1} and possible range extending
from 0 to the number of pixels in the image, MN .
The histogram is given explicitly by
H
f
(k) ϭ J (3.1)
if f contains exactly J occurrences of gray level k, for each k ϭ 0, ,K Ϫ 1. Thus, an
algorithm to compute the image histogram involves a simple counting of gray levels,
which can be accomplished even as the image is scanned. Every image processing
development environment and software librar y contains basic histogram computation,
manipulation, and display routines.
3.3 Image Histogram 45
Since the histogram represents a reduction of dimensionality relative to the original
image f , information is lost—the image f cannot be deduced from the histogram H
f
except in trivial cases (when the image is constant-valued). In fact, the number of images
that share the same arbitrary histogram H
f
is astronomical. Given an image f with a
particular histogram H
f
, every image that is a spatial shuffling of the gray levels of f has
the same histogram H
f

f
(
n
1
,n
2
)
(3.2)
or it can be computed from the image histogram:
AOD(f ) ϭ
1
NM
K Ϫ1

kϭ0
kH
f
(k). (3.3)
The AOD is a useful and simple meter for estimating the center of an image’s gray level
distribution. A target value for the AOD might be specified when designing a point
operation to change the overall gray level distribution of an image.
Figure 3.1 depicts two hypothetical image histograms. The one on the left has a heavier
distribution of gray levels close to zero (and a low AOD), while the one on the right is
skewed toward the right (a high AOD). Since image gray levels are usually displayed
with lower numbers indicating darker pixels, the image on the left corresponds to a
predominantly dark image. This may occur if the image f was originally underexposed
0 KϪ1Gray level k
H
f
(k)

The digital image “students” (left) and its histogram (right). The gray levels of this image are
skewed towards the left, and the image appears slightly underexposed.
0 KϪ1Gray level k
H
f
(k)
H
f
(k)
0 KϪ1Gray level k
FIGURE 3.3
Histograms of images that make poor (left) and good (right) use of the available grayscale range.
A compressed histogram often indicates an image with a poor visual contrast. A well-distributed
histogram often has a higher contrast and better visibility of detail.
3.4 Linear Point Operations on Images 47
3000
2000
1000
0
50 100 150 200 250
FIGURE 3.4
Digital image “books” (left) and its histogram (right). The image makes poor use of the available
grayscale range.
will often have a poor visual contrast or a“washed-out”appearance. If the grayscale range
is filled out, also depicted in Fig. 3.3, then the image tends to have a higher contrast and
a more distinctive appearance. As will be shown, there are specific point operations that
effectively expand the grayscale distribution of an image.
Figure 3.4 depicts the 256 ϫ 256 gray level image “books” and its histogram. The
histogram clearly reveals that nearly all of the gray levels that occur in the image fall
within a small range of grayscales, and the image is of correspondingly poor contrast.

The saturation conditions |g(n)|< 0 and |g (n)| > K Ϫ 1 are to be avoided if possible,
since the gray levels are then not properly defined, which can lead to severe errors in
processing or display of the result. The designer needs to be aware of this so steps can
be taken to ensure that the image is not distorted by values falling outside the range. If
a specific wordlength has been allocated to represent the gray level, then saturation may
result in an overflow or underflow condition, leading to very large errors. A simple way to
handle this is to simply clip those values falling outside of the allowable grayscale range
to the endpoint values. Hence, if |g (n
0
)| < 0 at some coordinate n
0
, then set |g(n
0
)| ϭ 0
instead. Likewise, if |g(n
0
)| > K Ϫ 1, then fix |g (n
0
)| ϭ K Ϫ 1. Of course, the result is no
longer strictly a linear point operation. Care must be taken since information is lost in
the clipping operation, and the image may appear artificially flat in some areas if whole
regions become clipped.
3.4.1 Additive Image Offset
Suppose P ϭ 1 and L is an integer satisfying |L|Յ K Ϫ 1. An additive image offset has the
form
g (n) ϭ f (n) ϩ L. (3.6)
Here we have prescribed a range of values that L can take. We have taken L to be an integer,
since we are assuming that images are quantized into integers in the range {0, ,K Ϫ 1}.
We have also assumed that |L| falls in this range, since otherwise, all of the values of g (n)
will fall outside the allowable grayscale range.

3000
2000
1000
0
50 100 150 200 250
FIGURE 3.6
Left: Additive offset of the image “students” in Fig. 3.2 by amount 60. Observe the clipping spike
in the histogram to the right at gray level 255.
Figures 3.6 and 3.7 show the result of applying an additive offset to the images
“students”and“books”in Figs. 3.2 and 3.4, respectively. In both cases,the overall visibility
of the images has been somewhat increased, but there has not been an improvement in the
contrast. Hence, while each image as a whole is easier to see, the details in the image are
no more visible than they were in the original. Figure 3.6 is a good example of saturation;
a large number of gray levels were clipped at the high end (gray level 255). In this case,
clipping did not result in much loss of information.
Additive image offsets can be used to calibrate images to a given average brightness
level. For example, suppose we desire to compare multiple images f
1
,f
2
, ,f
n
of the same
scene, taken at different times. These might be surveillance images taken of a secure area
that experiences changes in overall ambient illumination. These variations could occur
because the area is exposed to daylight.
50 CHAPTER 3 Basic Gray Level Image Processing
3000
2000
1000

Here P is assumed positive since g(n) must be positive. Note that we have not constrained
P to be an integer, since this would usually leave few useful values of P; for example, even
taking P ϭ 2 will severely saturate most images. If an integer result is required, then a
practical definition for the output is to round the result in (3.9):
g (n) ϭ INT[Pf (n) ϩ 0.5], (3.10)
where INT[R] denotes the nearest integer that is less than or equal to R.
The effect that multiplicative scaling has on an image depends largely on whether P
is larger or smaller than one. If P > 1, then the gray levels of g will cover a broader range
than those of f .Conversely,ifP < 1, then g w ill have a narrower g ray level distribution
than f . In terms of the image histogram,
H
g
{INT[Pk ϩ 0.5]} ϭ H
f
(k). (3.11)
Hence multiplicative scaling by a factor P either stretches or compresses the image
histogram. Note that for quantized images, it is not proper to assume that (3.11) implies
H
g
(k) ϭ H
f
(k/P) since the argument of H
f
(k/P) may not be an integer.
3.4 Linear Point Operations on Images 51
AB
0
PA PB
PBPA
B Ϫ A

visibility of detail that is less striking. However, these are only rules of thumb, and there
are exceptions. An image may have a grayscale spread that is too extensive, and may
benefit from scaling with P < 1.
Figure 3.9 shows the image “students” following a multiplicative scaling with P ϭ
0.75, resulting in compression of the histogram. The resulting image is darker and less
contrasted. Figure 3.10 shows the image “books” following scaling with P ϭ 2. In this
case, the resulting image is much brighter and has a better visual resolution of gray levels.
Note that most of the high end of the grayscale range is now used, although the low
end is not.
3.4.3 Image Negative
The first example of a linear point operation that uses both scaling and offset is the image
negative,whichisgivenbyP ϭϪ1 and L ϭ K Ϫ 1. Hence
g (n) ϭϪf (n) ϩ (K Ϫ 1) (3.12)
52 CHAPTER 3 Basic Gray Level Image Processing
4000
3000
2000
1000
0
50 100 150 200 250
FIGURE 3.9
Histogram compression by multiplicative image scaling with P ϭ 0.75. The resulting image is less
distinctive. Note also the regularly-spaced tall spikes in the histogram; these are gray levels that
are being “stacked,” resulting in a loss of information, since they can no longer be distinguished.
3000
2000
1000
0
50 100 150 200 250
FIGURE 3.10


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status