# AVL.LocateMultipleObjects_NCC2

Finds all occurrences of a predefined template on an image by analysing the normalized correlation between pixel values.

Namespace: AvlNet AVL.NET.dll

### Syntax

C++
C#

public static void LocateMultipleObjects_NCC2
(
AvlNet.Image inImage,
NullableRef<AvlNet.ShapeRegion> inSearchRegion,
AvlNet.CoordinateSystem2D? inSearchRegionAlignment,
AvlNet.GrayModel2 inGrayModel,
int inMinPyramidLevel,
int? inMaxPyramidLevel,
bool inIgnoreBoundaryObjects,
float inMinScore,
float inMinDistance,
float? inMaxBrightnessRatio,
float? inMaxContrastRatio,
IList<AvlNet.Object2D> outObjects,
out int outPyramidHeight,
AvlNet.ShapeRegion outAlignedSearchRegion,
IList<AvlNet.Image> diagImagePyramid,
IList<AvlNet.Image> diagMatchPyramid,
IList<List<float>> diagScores
)


### Parameters

Name Type Range Default Description
inImageAvlNet.ImageImage on which model occurrences will be searched.
inSearchRegionAvlNet.NullableRef<AvlNet.ShapeRegion>Range of possible object centers. Default value: atl::NIL.
inSearchRegionAlignmentAvlNet.CoordinateSystem2D?Adjusts the region of interest to the position of the inspected object. Default value: atl::NIL.
inGrayModelAvlNet.GrayModel2Model of objects to be searched.
inMinPyramidLevelint<0, 12>0Defines the lowest pyramid level at which object position is still refined. Default value: 0.
inMaxPyramidLevelint?<0, 12>3Defines the total number of reduced resolution levels that can be used to speed up computations. Default value: 3.
inIgnoreBoundaryObjectsboolFalseFlag indicating whether objects crossing image boundary should be ignored or not. Default value: False.
inMinScorefloat<-1.0f, 1.0f>0.7fMinimum score of object candidates accepted at each pyramid level. Default value: 0.7f.
inMinDistancefloat<0.0f, INF>10.0fMinimum distance between two found objects. Default value: 10.0f.
inMaxBrightnessRatiofloat?<1.0f, INF>Defines the maximal deviation of the mean brightness of the model object and the object present in the image. Default value: atl::NIL.
inMaxContrastRatiofloat?<1.0f, INF>Defines the maximal deviation of the brightness standard deviation of the model object and the object present in the image. Default value: atl::NIL.
outObjectsSystem.Collections.Generic.IList<AvlNet.Object2D>Found objects.
outPyramidHeightintHighest pyramid level used to speed up computations.
outAlignedSearchRegionAvlNet.ShapeRegionTransformed input shape region.
diagImagePyramidSystem.Collections.Generic.IList<AvlNet.Image>Pyramid of iteratively downsampled input image.
diagMatchPyramidSystem.Collections.Generic.IList<AvlNet.Image>Candidate object locations found at each pyramid level.
diagScoresSystem.Collections.Generic.IList<System.Collections.Generic.List<float>>Scores of the found objects at each pyramid level.

### Description

The operation matches the object model, inGrayModel, 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. The inMinDistance parameter determines minimum distance between any two valid occurrences (if two occurrences lie closer than inMinDistance from each other, the one with greater score is considered to be valid).

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.

To be able to locate objects which are partially outside the image, the filter assumes that there are only black pixels beyond the image border.

The outObjects.Point array contains the model reference points of the matched object occurrences. The corresponding outObjects.Angle array contains the rotation angles of the objects. The corresponding outObjects.Match array provides information about both the position and the angle of each match combined into value of Rectangle2D type. Each element of the outObjects.Alignment array contains informations about the transform required for geometrical objects defined in the context of template image to be transformed into object in the context of corresponding outObjects.Match position. This array can be later used e.g. by 1D Edge Detection or Shape Fitting categories filters.

### Examples

Locating multiple objects with the gray-based method (inMaxPyramidLevel = 2). Please note, that the edge-based method might not work properly here, because what we are looking for (a missing chip) is a sub-object of what we are not looking for (a correct chip).

### Remarks

Read more about Local Coordinate Systems in Machine Vision Guide: Local Coordinate Systems.

Additional information about Template Matching can be found in Machine Vision Guide: Template Matching

### Hardware Acceleration

This operation is optimized for SSE2 technology for pixels of type: UINT8.

This operation is optimized for AVX2 technology for pixels of type: UINT8.

This operation is optimized for NEON technology for pixels of type: UINT8.

This operation supports automatic parallelization for multicore and multiprocessor systems.

Hardware acceleration settings may be manipulated with Settings class.

### Errors

List of possible exceptions:

Error type Description
DomainError Invalid GrayModel2 in LocateMultipleObjects_NCC2. Create a proper model first using the Template Matching plugin or CreateGrayModel2 filter.