Workflowđź”—
Selecting the model ROIđź”—
As a first step of the correlation-based matching, the region of interest that specifies the template image must be selected. This region can have an arbitrary shape, that is, it can also contain holes or consist of several parts that are not connected. Thus, it is possible to create an ROI that contains only “robust” parts of the object.
In most cases, the ROI must be selected so that it contains also some pixels outside of the object of interest, as the immediate surroundings (neighborhood) of the object are needed to obtain the model. But if the object itself contains enough structure to be recognized independently from its outline, it can also be selected smaller than the object. Then, the object can be found also in front of different backgrounds.
Note
Note that you can speed up the later search using a subsampling. For that, the ROI should not be too “thin”, because otherwise it vanishes at higher pyramid levels! As a rule of thumb, you are on the safe side if an ROI is \(2^{NumLevels-1}\) pixels wide. That is, a width of 8 pixels allows to use 4 pyramid levels.
After having selected a suitable ROI, the reduced image is used as template image for the creation of the model.
Creating suitable NCC modelđź”—
Having derived the template image from the reference image, the NCC model can be created with the operator create_ncc_model.
Here, we will take a closer look at how to adjust the corresponding parameters:
- Use a subsampling to speed up the search by adjusting the parameter
NumLevels. - Allow a specific range of orientation by adjusting the parameters
AngleExtent,AngleStart, andAngleStep. - Specify which pixels are compared with the model in the later search, that is, specify the polarity of the object by adjusting the parameter
Metric.
For the parameters NumLevels and AngleStep, you can let HALCON suggest values automatically.
This can be done either by setting the parameters within create_ncc_model to the value 'auto'; then, if you need to know the values, you can query them using get_ncc_model_params.
Or you apply determine_ncc_model_params before you create the model.
Then, you get an estimation of the automatically determined values as suggestion so that you can still modify them for the actual creation of the model.
Note
Both approaches return only approximately the same values and the values returned by create_ncc_model are more precise.
After the creation of the model, the model can still be modified.
Using subsampling to speed up the searchđź”—
Affected parameter
NumLevels
To speed up the matching process, subsampling can be used. There, an image pyramid is created, consisting of the original, full-sized image and a set of downsampled images. The model is then created and searched on the different pyramid levels.
You can specify how many pyramid levels are used via the parameter NumLevels.
We recommend to let HALCON select a suitable value itself by specifying the value 'auto'.
You can then query the used value via the operator get_ncc_model_params.
Allowing a range of orientationđź”—
Affected parameters
AngleExtent, AngleStart, AngleStep
If the object’s rotation may vary in the search images you can specify the allowed range in the parameter AngleExtent and the starting angle of this range in the parameter AngleStart (unit: radians).
We recommend to limit the allowed range of rotation as much as possible in order to speed up the search process.
During the matching process, the model is searched for in different angles within the allowed range, at steps specified with the parameter AngleStep.
If you select the value 'auto', HALCON automatically chooses an optimal step size to obtain the highest possible accuracy by determining the smallest rotation that is still discernible in the image.
The tips for the selection of values for all three parameters given for shape-based matching are also valid for correlation-based matching.
Specifying how gray values are compared with the modelđź”—
Affected parameter
Metric
The parameter Metric lets you specify whether the polarity, that is, the “direction” of the contrast must be observed.
If you select the value 'use_polarity' the polarity is observed, that is, the points in the search image must show the same direction of the contrast as the corresponding points in the model.
If, for example, the model is a bright object on a dark background, the object is found in the search images only if it is also brighter than the background.
You can choose to ignore the polarity globally by selecting the value 'ignore_global_polarity'.
In this mode, an object is recognized also if the direction of its contrast reverses, for example, if your object can appear both as a dark shape on a light background and vice versa.
This flexibility, however, is obtained at the cost of a slightly lower recognition speed and reduced robustness.
Inspecting and modifying the NCC modelđź”—
To inspect the current parameter values of the model, you query them with get_ncc_model_params.
This may be necessary if during the creation of the model an automatic parameter selection was used or if the model was created within another program, saved to file with write_ncc_model and read from this file in the current program with read_ncc_model.
Additionally, you can query the coordinates of the origin of the model using get_ncc_model_origin.
After the creation of the model and before you search the object in a search image, you can further modify the model.
In particular, you can apply set_ncc_model_param to change individual parameters and set_ncc_model_origin to change the origin of the model.
The latter is not recommended because the accuracy of the matching result may decrease, which is shown in more detail for shape-based matching.