nearest_neighbour
- arrayfire.nearest_neighbour(query: Array, train: Array, /, axis: int = 0, n_nearest: int = 1, match_type: Match = Match.SSD) tuple[Array, Array]
Finds the nearest neighbors for each descriptor in a query set from a training set based on a specified metric.
Parameters
- queryArray
The query set of feature descriptors as an ArrayFire array. Each descriptor should be aligned along the specified axis in a multidimensional array.
- trainArray
The training set of feature descriptors as an ArrayFire array. This serves as the database from which the closest matches to the query descriptors are found.
- axisint, default=0
The dimension along which the feature descriptors are aligned. For a 2D array of descriptors, this is typically 0, indicating that each descriptor is a row.
- n_nearestint, default=1
The number of nearest neighbors to find for each query descriptor. Allows for finding multiple matches per query.
- match_typeMatch, default=Match.SSD
The matching metric to use for finding nearest neighbors. Match.SSD uses the sum of squared differences, suitable for floating-point descriptors. Other metrics can be specified if supported.
Returns
- tuple[Array, Array]
A tuple containing two ArrayFire arrays: - The first array contains the indices of the closest matches in the training set for each query descriptor. - The second array contains the distances of these matches according to the specified metric.
Note
The nearest_neighbour function is versatile, supporting various descriptor types and matching metrics. It is particularly useful in computer vision tasks such as object recognition, where matching feature descriptors between images is essential.