
B-20 General Topics
2.1.1 Reduce the Reference Image to a Template Image
To create a model from a reference image, which is the common way for most matching approaches, the
reference image must be reduced to a template image that contains only those structures of the reference
image that are needed to derive the model.
For this, you select a region within the reference image that shows the part of the image that should serve
as the template or, respectively, from which the model should be derived. After selecting the region, the
domain of the reference image is reduced to an ROI using the operator reduce_domain. The resulting
image is our template image, which is input to one of the approach-specific operators that are provided
for the actual model generation.
Note that a region and therefore also the model can have an arbitrary shape (see the Quick Guide, sec-
tion 2.1.2.2 on page 17 for the exact definition of regions in HALCON). A region can be created in
different ways, as is described in the Solution Guide I, chapter 3 on page 19 and chapter 4 on page 31.
Summarized, a region can be selected, e.g., by the following means:
• A region can be specified by explicitly defining its parameters. That is, HALCON offers mul-
tiple operators to create regions, ranging from standard shapes like rectangles (gen_rectangle2)
or ellipses (gen_ellipse) to free-form shapes (e.g., gen_region_polygon_filled). These
operators can be found in the HDevelop menu Operators . Regions . Creation. To use the
operators, you need the parameters of the shape you want to create, e.g., the position, size, and
orientation of a rectangle or the position and radius of a circle. If these parameters are not explic-
itly known, you can get them using draw operators, i.e., operators that let you draw a shape on the
displayed image and then return the shape parameters. These operators are available, e.g., in the
HDevelop menu Operators . Graphics . Drawing.
• A region can be specified by image processing using, e.g., a blob analysis. Then, the image is
segmented, e.g., using a threshold operator, and the obtained region is further processed to select
only those parts of it having specific features (commonly applied operators are, e.g., connection,
fill_up, and select_shape). In HDevelop, you can determine suitable features and values
using the dialog Visualization . Feature Inspection. More complex regions can be created
using set theory, i.e., by adding or subtracting standard regions using the operators union2 and
difference. That way, e.g., also ring-shaped ROIs can be created like is shown in section 2.1.2.2
on page 22.
Before creating the ROI, it is often suitable to optimize the reference image by a preprocessing. Note
that when using shape-based matching, you can use an HDevelop Assistant that guides you through the
matching process, which includes also the preprocessing of the reference image as well as the creation
of the ROI. How to use the Matching Assistant is described in the HDevelop User’s Guide, section 6.3
on page 221.
Note that also the gray values outside of the ROI have an influence on the model generation. In particular,
the influence is approximately 2
NumLevels
pixels, with n being the number of pyramid levels. Thus, the
gray values outside of the ROI selected in the reference image should be similar to those that will occur
in the search images.