Preparing a pattern for template matching.
The operator create_template preprocesses a pattern (Template), which is passed as an image, for the template matching. After the transformation, a number (TemplateID) is assigned to the template for being used in the further process. The shape and the size of Template can be chosen arbitrarily. You have to be aware, that the matching is only applied to that part of an image where Template fits completely into the image.
The template has be chosen such that it contains no pixels of the (changing) background. Here you can make use of the artitrary shape of a template which is not restricted to a rectangle. To create a template you can use segmentation operators like threshold. In the case of sub pixel accurate matching Template has in addition to be one pixel smaller than the pattern (i.e. one pixel border to the changing background). This can be done e.g. by applying the operator erosion_circle.
The parameter NumLevel specifies the number of pyramid levels (NumLevel = 1 means only original gray values) which can be used for matching. The number of levels used later for matching will be below or equal this value. If the pattern becomes to small due to zooming, the maximum number of pyramid levels is automatically reduced (without error message).
The parameter GrayValues defines, wheter the original gray values ('original', 'normalized) or the edge amplitude ('gradient', 'sobel') is used. With 'original' the sum of the differences is used as feature which is very stable and fast if there is no change in illumination. 'normalized is used if the illumination changes. The method is a bit slower and not quite as stable. If there is no change in illumination the mode 'original' should be used. The edge amplitude is another method to be invariant to changes in illumination. The disadvantage is the increased execution time and the higher sensitivity to changes in the shape of the pattern. The mode 'gradient' is slighy faster but more sensitive to noise.
The maximum error for matching has typically to be chosen higher when using the edge amplitude. The mode chosen by GrayValues leads automatically to calling the appropriate filter during matching --- if necessary.
As an alternative to the gradient approach the operator set_offset_template can be used, if the change in illumination is known.
The parameter Optimize specifies if the pattern has to optimized for runtime. This optimization results in a longer time to create the template but reduces the time for matching. In addition the optimization leads to a more stable matching, i.e., the possibilty to miss good matches is reduced. The optimization process selects the most stable and significant gray values to be tested first during the matching process. Using this technique a wrong match can be eliminated very early.
The reference position for the template is its center of gravity. I.e. if you apply the template to the original image the center of gravity is returned. This default reference can be adapted using the operator set_reference_template.
In sub pixel mode a special position correction is calculated which is added after each matching: The template is applied to the original image and the difference between the found position and the center of gravity is used as a correction vector. This is important for patterns in a textured context or for asymetric pattern. For most templates this correction vector is near null.
If the pattern is no longer used, it has to be freed by the operator clear_template in order to deallocate the memory.
Before the use of the template, which is stored independently of the image size, it can be adapted explicitly to the size of a definite image size by using adapt_template.
|
Template (input_object) |
image -> object : byte |
| Input image whose domain will be processed for the pattern matching. | |
|
FirstError (input_control) |
integer -> integer |
| Not yet in use. | |
| Default value: 255 | |
| List of values: 255 | |
|
NumLevel (input_control) |
integer -> integer |
| Maximal number of pyramid levels. | |
| Default value: 4 | |
| List of values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 | |
|
Optimize (input_control) |
string -> string |
| Kind of optimizing. | |
| Default value: 'sort' | |
| List of values: 'none', 'sort' | |
|
GrayValues (input_control) |
string -> string |
| Kind of grayvalues. | |
| Default value: 'original' | |
| List of values: 'original', 'normalized', 'gradient', 'sobel' | |
|
TemplateID (output_control) |
template -> integer |
| Template number. | |
If the parameters are valid, the operator create_template returns the value 2 (H_MSG_TRUE). If necessary an exception handling will be raised.
create_template is processed completely exclusively without parallelization.
draw_region, reduce_domain, threshold
adapt_template, set_reference_template, clear_template, write_template, set_offset_template, best_match, best_match_mg, fast_match, fast_match_mg
create_template_rot, read_template
Matching