Sie sind auf Seite 1von 13

85

5

Image Processing

Once you have acquired images, they are often not in an appropriate format for you
to analyze and must be processed rst. The Vision Toolkit contains many tools to
help you clean up and alter images, from dening a region of interest to ltering
and spatial manipulation.

5.1 THE ROI (REGION OF INTEREST)

A ROI is a specication structure that allows for the denition of arbitrarily shaped
regions within a given image, often called subimages (although a ROI can encompass
the entire image if so dened). A ROI contains no image data - it is not an image
itself, but a placeholder that remembers a dened location within an image.
Why would you need a ROI within an image? Why not just acquire the region
of interest as the complete image? There are many answers to this question: rst,
ROIs can be irregular shapes - not necessarily the rectangle or square that your
camera supplies. ROIs can be rectangles or squares (a square is often called an

area
of interest

, or AOI), circles, annuluses, polygons and freehand shapes. Secondly, you
may want to perform different image processing routines on different areas of an
image - there is no sense in wasting valuable time on processing the whole raw
image, when you are only interested in a few small parts of it. Another reason for
ROIs is that you can dynamically dene and change them - users can draw a ROI
over a portion of an image at run time, selecting their particular region of interest.
The license plate in Figure 5.1 has a dened ROI around the alphanumeric
characters, to make it much simpler and faster for an optical character recognition
(OCR) routine to decode. Also, the routine would try to recognize characters where
none are present, perhaps returning erroneous results.

FIGURE 5.1

Car license plate with a dened ROI

1480book.Im Page 85 Friday, April 25, 2003 3:25 PM
86

Image Acquisition Processing with LabVIEW

By traditional denition, every point of an image is either inside or outside of
a given ROI. The Vision Toolkit takes this denition one step further by adding two
new ROI concepts: the line and the point. Strictly speaking, these ROI types are not
actually lines and points, but a single pixel width rectangle and square respectively.
Points are useful to return single value data about a region of your image (point
intensity, color data, etc) and the line can return one-dimensional information.

5.1.1 S

IMPLE

ROI U

SE

5.1.1.1 Line

A simple ROI example is that of an intensity contour measurement, as shown in
Figure 5.2 and Figure 5.3. The

IMAQ



WindLastEvent

VI is used to detect the event
that last occurred in the nominated IMAQ window and looks for a draw event
(suggesting that the user has drawn a ROI of some type).

IMAQ WindGetROI

then
returns the denition of the created ROI and

IMAQ ROI Profile

returns the intensity
contours along the length of the ROI (if a two-dimensional ROI is dened, the
intensity contours follow the outer shape of the ROI, starting at the rst dened
point).



As you can see, the initial ROI point is that on the far left and as the line is
followed, the intensity levels are returned (suggesting that the background intensity
of the license plate is approximately 240 units, whereas the alphanumeric characters
are approximately 50 units).

5.1.1.2 Square and Rectangle

A square ROI is the simplest two-dimensional ROI - it allows the user to select a
region with four equal sides, although the rectangle ROI is probably the most popular,
allowing the user more exibility in dening the required region.

FIGURE 5.2

Simple ROI intensity contour - wiring diagram.

1480book.Im Page 86 Friday, April 25, 2003 3:25 PM
Image Processing

87

Figure 5.4 shows intensity contour information for a rectangular ROI - the
contours are plotted from the rst dened corner of the ROI (the top left corner in
this case), along the ROI in a clockwise direction. As they are two-dimensional
ROIs, they have several other applications, including image portion selection (See
Figure 5.5).

FIGURE 5.3

A line ROI, with its calculated intensity contour.

FIGURE 5.4

Rectangle ROI contour example

1480book.Im Page 87 Friday, April 25, 2003 3:25 PM
88

Image Acquisition Processing with LabVIEW

Image portion selection is achieved by rst converting a detected ROI to a
rectangle and then extracting the portion of the source image that is bound by that
rectangle using

IMAQ Extract

, as shown in Figure 5.6.

5.1.1.3 Oval

An oval ROI is dened by rst holding down the left mouse button to dene the
center and then dragging to dene the radii of the ROI:
As you can see from Figure 5.7, the position of the mouse cursor during the
drag operation may not be particularly intuitive, but it is a corner of the oval`s
bounding rectangle.

5.1.2 C

OMPLEX

ROI

S

Although simple ROIs can be very useful in particular situations, several other types
are available, including the rotated rectangle and annulus arc.

FIGURE 5.5

Two-dimensional ROI image portion selection.

FIGURE 5.6

Two-Dimensional ROI image portion selection - wiring diagram.

1480book.Im Page 88 Friday, April 25, 2003 3:25 PM
Image Processing

89

5.1.2.1 Rotated Rectangle

As its name would suggest, rotated rectangles are similar to their simple counterparts,
but with the added functionality of allowing the user to rotate them. When a rotated
square or rectangle is dened, several extra construction lines are evident (Figure 5.8).
The masked rotated rectangle ROI in Figure 5.8 was achieved with the code
shown in Figure 5.9.

5.1.2.2 Annulus Arc

An annulus is dened as the gure bounded by and containing the area between
two concentric circles and an annulus arc is, as you might expect, an arc component
of that annulus (Figure 5.10).
An annulus arc is very useful when unwrapping text, or any otherwise wrapped
image data, for analysis. Dening an annulus arc takes place in four steps, as shown
in Figure 5.11(a) dening the outer radius, Figure 5.11(b) the starting edge, Figure
5.11(c) the ending edge and Figure 5.11(d) the inner radius.
Using the Annulus Arc selection tool alone may seem of little or no use, if it is
combined with an unwrapping routine (

IMAQ Unwrap,

for example) you can unwrap
a semicircular portion of an image, distorting it to a rectangular shape, as shown in
Figure 5.12. This example waits for a Draw Event on either of the IMAQ windows
and once one is detected, that window`s ROI is returned, converted from a raw ROI
to an annulus arc and then

IMAQ Unwrap

is called to unwrap the annulus arc into a
rectangle.
The unwrapped image (the oating window containing the text in Figure 5.13)
can then be fed through optical character recognition (OCR) software, including the

FIGURE 5.7

Oval ROI denition.

1480book.Im Page 89 Friday, April 25, 2003 3:25 PM
90

Image Acquisition Processing with LabVIEW

National Instruments OCR Toolkit add-on for the Vision Toolkit (see Chapter 8 for
more information about OCR).

FIGURE 5.8

(a) Drag out a standard rectangular ROI. (b) Rotate the ROI with the handles.
(c) Rotated rectangular ROI.

FIGURE 5.9

Rotated rectangle ROI image portion selection - wiring diagram.

1480book.Im Page 90 Friday, April 25, 2003 3:25 PM
Image Processing

91
FIGURE 5.10

Annulus arc components.

FIGURE 5.11

(a) Dening the outer radius. (b) Dening the starting edge. (c) Dening the
ending edge. (d) Dening the inner radius.
Drag Point
Outer Radius
Inner
Radius
Start Edge
End Edge

1480book.Im Page 91 Friday, April 25, 2003 3:25 PM
92

Image Acquisition Processing with LabVIEW

5.1.2.3 ROI Tracing Example

A user recently posted a question on the National Instruments Developer`s Zone
discussion forum:

I am currently working on a project using LabVIEW 6.0 and IMAQ Vision [and] I
need to get the . coordinates of the cursor in an IMAQ window. .

The project called for the user to drag the mouse pointer over an image and then
track a laser beam along the same coordinates. Although previous examples in this
book have used

IMAQ



WindLastEvent

to determine only the type of event that has
occurred, it can also provide us with some limited information regarding the event`s

FIGURE 5.12

Unwrap annulus arc ROI - wiring diagram.

FIGURE 5.13

Unwrap annulus arc ROI.

1480book.Im Page 92 Friday, April 25, 2003 3:25 PM
Image Processing

93

attributes. The VI has three outputs of interest:

event, coordinates

and

other param-
eters,

which are populated as shown in Table 5.1.
In this instance, the user was able to use the

draw vertices

data returned in the

coordinates

array, which was subsequently built into an array of clusters (each
containing the

x,y

pair of the pixels that were traced over). This allowed the user to
trace the path of the mouse (Figure 5.15).
As you can see in Figure 5.14, the

coordinates

array returns the start and end
point of the freehand draw operation, as well as the vertices of each point along the
way:

5.1.3 M

ANUALLY

B

UILDING



A

ROI: T

HE

ROI D

ESCRIPTOR


It is often benecial to programmatically dene ROIs, especially if there are several
objects of interest that are always in the same place within a series of images (e.g.,

TABLE 5.1

Event ROI Tool Coordinates [Array] Other Parameters [Array]

None Any NULL NULL
Click Cursor [0,1] xy position of the click [0,1,2] selected pixel intensity
Double click Any [0,1] xy position of the click [0,1,2] selected pixel intensity
Zoom [0,1] xy position of the click
[2,3] image xy center position
[0] new zoom factor
Draw Line [0,1] xy start point
[2,3] xy end point
[0] bounding rectangle width
[1] bounding rectangle height
[2] vertical segment angle
Rectangle [0,1] xy start point
[2,3] xy end point
[0] width
[1] height
Oval [0,1] bounding rectangle start
point
[2,3] bounding rectangle end
point
[0] bounding rectangle width
[1] bounding rectangle height
Polygon [0,1] bounding rectangle start
point
[2,3] bounding rectangle end
point
[4,5], [6,7], [8,9] . vertices
[0] bounding rectangle width
[1] bounding rectangle height
Freehand [0,1] bounding rectangle start
point
[2,3] bounding rectangle end
point
[4,5],[6,7],[8,9]. vertices
[0] bounding rectangle width
[1] bounding rectangle height
Move Any [0,1] new position of the window NULL
Size Any [0] new width of the window
[1] new height of the window
NULL
Scroll Any [0,1] new center position of image NULL

1480book.Im Page 93 Friday, April 25, 2003 3:25 PM
94

Image Acquisition Processing with LabVIEW

parts on a production line). Setting the upper left and lower right corners is not
enough to fully dene a ROI, as it contains several other attributes. The ROI itself
is carried around LabVIEW diagrams as a special cluster called the

ROI Descriptor

(Figure 5.16; Table 5.2).
Figure 5.17 is an example of a dynamically dened rectangular ROI. As the user
changes the

Manual Rect ROI

values, a new ROI Descriptor is calculated with an
internal ID. The image data within the ROI is then extracted and displayed as a new

FIGURE 5.14

Trace mouse cursor example.

FIGURE 5.15

Trace mouse cursor example - wiring diagram.

1480book.Im Page 94 Friday, April 25, 2003 3:25 PM
Image Processing

95

image (the example in Figure 5.18 uses the global rectangle as the coordinates, as
the type is a rectangle).
One often-useful application of dynamic ROI denition is an

inspection routine

,
which allows the user to pan and zoom a source image to locate features (Figure
5.19).
Although the wiring diagram in Figure 5.20 may look complicated, it is just an
extension of previous examples. An event handler waits on the user pressing one of
the inspection navigation buttons on the front panel and adjusts either the window
zoom or ROI descriptor to suit. The new values are then fed into

IMAQ WindZoom

and

IMAQ WindSetROI

and the inspection window is redrawn to reect the changes.

FIGURE 5.16

The ROI descriptor.

TABLE 5.2

Item Description

Global rectangle The bounding box of the ROI - a rectangle whose bottom side is parallel
to the bottom of the source image and encloses the complete ROI,
irrespective of the ROI`s shape.
Contours Accurately dene the ROI with the following components:

ID:

Species whether the ROI is considered to be within or without the
dened shape. If the ID is external, the ROI is the complete image
outside of the ROI coordinates and is not bound by the global
rectangle.

Type:

Species the contour shape (Point, Line, Rectangle, Oval,
Polygon, Free, Broken Line, or Free Hand Line).

Coordinates:

Species the list of contour points (e.g., the top left and
bottom right points for a rectangle)
R
O
I
Global Rectangle
Source Image
Coordinates
Internal ID

1480book.Im Page 95 Friday, April 25, 2003 3:25 PM
96

Image Acquisition Processing with LabVIEW

FIGURE 5.17

Manually building a rectangular ROI.

FIGURE 5.18

Manually building a rectangular ROI - wiring diagram.

FIGURE 5.19

Manual rectangular ROI application.

1480book.Im Page 96 Friday, April 25, 2003 3:25 PM
Image Processing

97
FIGURE 5.20

Manual rectangular ROI application - wiring diagram.

1480book.Im Page 97 Friday, April 25, 2003 3:25 PM

Das könnte Ihnen auch gefallen