Find nearest neighbors of a point
[indices,dists] = findNearestNeighbors(ptCloud,point,K,Name, Value)
point— Query point
Query point, specified as an [X,Y,Z] vector.
K— Number of nearest neighbors
Number of nearest neighbors, specified as a positive integer.
comma-separated pairs of
the argument name and
Value is the corresponding value.
Name must appear inside single quotes (
' '). You can
specify several name and value pair arguments in any order as
'Sort'— Sort indices
Sort indices, specified as a logical scalar. When you set
the returned indices are sorted in the ascending order based on the
distance from a query point. To turn sorting off, set
'MaxLeafChecks'— Number of leaf nodes
inf(default) | integer
Number of leaf nodes, specified as an integer. Set
the number of leaf nodes to search in the Kdtree. When you set this
inf, the entire tree is searched. When
the entire tree is searched, it produces exact search results. Increasing
the number of leaf nodes to check increases accuracy, but reduces
indices— Indices of stored points
Indices of stored points, returned as a column vector. The
contains K linear indices to the stored points in the point cloud.
dists— Distances to query point
Distances to query point, returned as a column vector. The
K Euclidean distances to the query point.
Create a point cloud object with randomly generated points.
ptCloud = pointCloud(1000*rand(100,3,'single'));
Define a query point and the number of neighbors.
point = [50,50,50]; K = 10;
Get the indices and the distances of 10 nearest points.
[indices,dists] = findNearestNeighbors(ptCloud,point,K);
Muja, M. and David G. Lowe. "Fast Approximate Nearest Neighbors with Automatic Algorithm Configuration". In VISAPP International Conference on Computer Vision Theory and Applications. 2009. pp. 331–340.