You are here: Start » Filter Reference » Computer Vision » Template Matching » LocateSingleObject_Edges1
Finds a single occurrence of a predefined template on an image by comparing object edges.
|inImage||Image||Image on which object occurrence will be searched|
|inSearchRegion||ShapeRegion*||Region of possible object centers|
|inSearchRegionAlignment||CoordinateSystem2D*||Adjusts the region of interest to the position of the inspected object|
|inEdgeModel||EdgeModel||Model of objects to be searched|
|inMinPyramidLevel||Integer||0 - 12||Defines the lowest pyramid level at which object position is still refined|
|inMaxPyramidLevel||Integer*||0 - 12||Defines the total number of reduced resolution levels that can be used to speed up computations|
|inEdgeThreshold||Real||0.01 -||Minimum strength of edges used for matching with the model|
|inEdgePolarityMode||EdgePolarityMode||Defines how edges with reversed polarity will contribute to the object score|
|inEdgeNoiseLevel||EdgeNoiseLevel||Defines how much noise the object edges have|
|inIgnoreBoundaryObjects||Bool||Flag indicating whether objects crossing image boundary should be ignored or not|
|inMinScore||Real||0.0 - 1.0||Minimum score of object candidates accepted at each pyramid level|
|outObjectEdges||PathArray?||Model edges of the found object|
|outPyramidHeight||Integer||Highest pyramid level used to speed up computations|
|outAlignedSearchRegion||ShapeRegion||Transformed input shape region|
|diagEdgePyramid||ImageArray||Image edges used for matching at each pyramid level|
|diagMatchPyramid||ImageArray||Candidate object locations found at each pyramid level|
|diagScores||RealArray?||Scores of the found object at each pyramid level|
The operation matches the object model, inEdgeModel, against the input image, inImage. The inSearchRegion region restricts the search area so that only in this region the centers of the objects can be presented. The inMinScore parameter determines the minimum score of the valid object occurrence.
In the inImage every pixel with gradient's magnitude at least inEdgeThreshold is considered an edge pixel. Only those are later used during the matching process. To establish the value of this threshold properly the diagEdgePyramid output which shows all the edges with sufficient gradient's magnitude may be used. If the inEdgePolarityMode parameter is set to Ignore, the object occurrences in the inImage image do not have necessarily to have the same contrast as the object in the model image.
The computation time of the filter depends on the size of the model, the sizes of inImage and inSearchRegion, but also on the value of inMinScore. This parameter is a score threshold. Based on its value some partial computation can be sufficient to reject some locations as valid object instances. Moreover, the pyramid of the images is used. Thus, only the highest pyramid level is searched exhaustively, and potential candidates are later validated at lower levels. The inMinPyramidLevel parameter determines the lowest pyramid level used to validate such candidates. Setting this parameter to a value greater than 0 may speed up the computation significantly, especially for higher resolution images. However, the accuracy of the found object occurrences can be reduced. Larger inMinScore generates less potential candidates on the highest level to verify on lower levels. It should be noted that some valid occurrences with score above this score threshold can be missed. On higher levels score can be slightly lower than on lower levels. Thus, some valid object occurrences which on the lowest level would be deemed to be valid object instances can be incorrectly missed on some higher level. The diagMatchPyramid output represents all potential candidates recognized on each pyramid level and can be helpful during the difficult process of the proper parameter setting.
The outObject.Point contains the model reference point of the matched object occurrence. The outObject.Angle contains the rotation angle of the object. The outObject.Match provides information about both the position and the angle of the found match combined into value of Rectangle2D type. The outObject.Alignment contains information about the transform required for geometrical objects defined in the context of template image to be transformed into object in the context of outObject.Match position. This value can be later used e.g. by 1D Edge Detection or Shape Fitting categories filters.
- Connect the inImage input with the image you want to find objects on. Make sure that this image is available (the program was previously run).
- Click the "..." button at the inEdgeModel input to open the GUI for creating template matching models.
- The template region you select on the first screen should contain characteristic edges of the object, but should not be too big. In most cases you should NOT select the entire object here!
- IMPORTANT: The template region should encompass a clean margin of 10-30 pixels around the detected edges, so that these edges are also detected correctly at higher pyramid levels (when the template image is downsampled).
- If edges selected for the model (displayed in red) are incomplete or excessive try manipulating inSmoothingStdDev, inEdgeMagnitudeThreshold and inEdgeHysteresis as in 2D Edge Detection filters.
- Make sure that the inMinAngle / inMaxAngle range corresponds to the expected range of object rotations. This can have big influence on execution time.
- If you expect the object to appear at different scales, modify the inMinScale and inMaxScale parameters. Use it with care as it affects the speed.
- Do not use simultaneously wide ranges of rotations and scaling as the resulting model may become extremely large.
- On the second page (after clicking "Next") define the object rectangle that you want to get as the results. Please note that the rotation of this rectangle defines the object rotation, which is constrained by the inMinAngle / inMaxAngle parameters.
- You can use EnhanceSingleObjectMatch filter to fine-tune the results. A great example of usage is presented in the CreateGoldenTemplate2 filter.
- If an object is not detected, first try decreasing inMaxPyramidLevel, then try decreasing inMinScore.
- If all the expected objects are correctly detected, try achieving higher performance by increasing inMaxPyramidLevel and inMinScore.
- Please note, that due to the pyramid strategy used for speeding-up computations, some objects whose score would finally be above inMinScore may be not found. This may be surprising, but this is by design. The reason is that the minimum value is used at different pyramid levels and many objects exhibit lower score at higher pyramid levels. They get discarded before they can be evaluated at the lowest pyramid level. Decrease inMinScore experimentally until all objects are found.
- If precision of matching is not very important, you can also gain some performance by increasing inMinPyramidLevel.
- If the performance is still not satisfactory, go back to model definition and try reducing the range of rotations and scaling as well as the precision-related parameters: inAnglePrecision, inScalePrecision and inEdgeCompleteness.
- To obtain high accuracy of matching make sure that the edges visible on the diagEdgePyramid output are not too thick. Increase inEdgeThreshold to make them thinner.
- Also consider increasing inEdgeThreshold if there is much noise on the diagEdgePyramid output.
- Verify accuracy of the matching by checking the outObjectEdges output. If the accuracy is lower than expected, make sure that inMinPyramidLevel = 0, try increasing inEdgeThreshold and also consider higher values for inAnglePrecision during model creation.
- To further improve matching accuracy use the EnhanceSingleObjectMatch filter.
- If the object being detected can be darker or brighter than the background on different images, use the inEdgePolarityMode parameter set to Ignore.
- If the object being detected is only partially visible or its shape and the model shape are not identical, use the inEdgePolarityMode parameter set to MatchWeakly.
- If there is only low noise in the object edges, use the inEdgeNoiseLevel parameter set to Low.
- Define inSearchRegion to limit possible object locations and speed-up computations. Please note, that this is the region where the outObject.Point results belong to (and NOT the region within which the entire object has to be contained).
Read more about Local Coordinate Systems in Machine Vision Guide: Local Coordinate Systems.More informations about creating models can be found in article: Creating Models for Template Matching.
Additional information about Template Matching can be found in Machine Vision Guide: Template Matching
This operation supports automatic parallelization for multicore and multiprocessor systems.
This filter can throw an exception to report error. Read how to deal with errors in Error Handling.
List of possible exceptions:
|DomainError||Unsupported IgnoreGlobally edge polarity mode in LocateSingleObject_Edges1.|
This filter is available on Basic Complexity Level.
This filter is member of LocateObjects_Edges1 filter group.
- LocateMultipleObjects_Edges1 – Finds all occurrences of a predefined template on an image by comparing object edges.
- CreateEdgeModel1 – Creates a model for edge-based template matching.
- EnhanceSingleObjectMatch – Improves accuracy of single object matching by adding a subpixel-precise adjustment.