Shape-based matching with MVTec HALCON: speedup vs. robustness, advanced parameters

Hello and welcome. In the last two videos, we took a first look
at shaped-based matching, and how to process the results of the matching. In this video, we will take a look at some
advanced parameters that might help you if your application doesn’t
find all matches, for example because they are blurred, or deformed. Additionally, we will discuss how to speed
up your matching. First, we want to take a look at a parameter
that deals with a basic functionality of shape-based matching: NumLevels. Internally, shape-based matching works with
image pyramids. This means that the size of both the image
and the model are reduced repeatedly. The search for matches is first performed
in the low-resolution image, which is very fast. Based on the result,
the search area is limited in the following pyramid level. Thus, the model doesn’t have to be searched
in the complete image, saving time. In create_shape_model, NumLevels specifies
how many image pyramid levels are created. If it is set to ‘auto’, the number of levels
is determined automatically, based on the size of the object. In find_shape_model, you can either limit
the pyramid levels further, or you can set it to ‘zero’ to use all levels
that were created with create_shape_model. Using the operator inspect_shape_model,
you can get a good impression of the pyramid levels. If NumLevels is chosen too high, some matches
may be lost because they couldn’t be recognized in a low-resolution
image. On the other hand, if you begin the search
on a lower pyramid level, it may take a long time because of the high
resolution. Alternatively, you can skip these lower levels
in the search, by passing a tuple like [4,2]. Now, your search begins in the fourth pyramid
level, and ends in the second level. Thus, you can improve the runtime of your
application. The accuracy, however, might decrease. Sometimes, images are of poor quality, for
example because they are blurred. Thus, your matches might not be found at the
lowest pyramid level, because the edges are not clear enough. Nevertheless, the edge information may be
sufficient on higher pyramid levels. In NumLevels, we can pass the tuple [4, -2]. The minus in front of the 2 activates the
‘increased tolerance mode’, which means that if no instance of the model
can be found on this pyramid level, HDevelop determines the lowest pyramid level
on which at least one instance of the model can be found. Thus, matches which are blurred can be found. If the shape-based matching can’t find all
matches, one reason might be that the objects are slightly
deformed, like these paper clips. Using the parameter SubPixel,
you can specify how much a match might be deformed, in pixels. This can be really powerful, but it may increase
runtime. In many applications, you might consider using
an image with a reduced domain as the input image for
find_shape_model. For example, here we have an object on an
irregular background. We’re trying to find this cross. When running find_shape_model as usual,
we notice that it takes a long time to run because the size of the model is quite small
in relation to the size of the image. This means that few pyramid levels can be
used. Additionally, false matches are found. Instead, we can do a simple thresholding,
and then some blob analysis. From here, we can reduce the domain of the
image so that we only search the part of the image
where the object is located. In sum, the time required for these operations
is much lower. Additionally, like in this example,
you might be able to avoid false matches with this method. You may have noticed that the region of interest
is really small. The matches don’t have to lie completely in
the region of interest. It is enough if the center of gravity
of the original model is inside the region of interest. Next, let’s have a look at the parameter ‘Metric’
used in the operator create_shape_model. The standard value is ‘use_polarity’,
which means that if your object is bright and the background is dark,
only objects which are bright on a dark background will be found. With ‘ignore_global_polarity’,
you could additionally find all matches where the object is dark
and the background is bright as well. This has only a small impact on runtime. Finally, with ‘ignore_local_polarity’,
it’s possible to find matches where the contrast changes locally. This mode can be really helpful
if you have to deal with illumination changes, but it increases runtime. There are many additional parameters
you might want to take a look at to improve the performance of your application. For example, in find_shape_model,
Greediness can be used to tweak the runtime. Lastly, there are additional operators like
create_scaled_shape _model and find_scaled_shape_model if you deal with matches that may vary in
size. As you see, shape-based matching is a very
powerful tool. If you have additional questions, have a look
at HALCON’s extensive documentation, including the Solution Guide on Matching. Check out our YouTube channel for more tutorials
and information about our products. Thank you for watching.

2 Replies to “Shape-based matching with MVTec HALCON: speedup vs. robustness, advanced parameters”

  1. The link in the comment is invalid. Correct link:

Leave a Reply

Your email address will not be published. Required fields are marked *