pypose.knn_filter¶
- class pypose.knn_filter(points, k, pdim=None, radius=None, ord=2)[source]¶
Filter batched points by averaging its k-nearest neighbors and that point, removing points if number of neighbors within radius is less than k.
- Parameters:
points (
torch.Tensor
) – the input point cloud, where the last dimension (D) is the dimension of the points. The shape should be (…, N, D), where N is the number of points in each batch.k (
int
) – the number of neighbors within a radius.pdim (
int
, optional) – the dimsion of points, where \(\text{pdim} \le D\). Default to the last dimension of points, ifNone
.radius (
float
, optional) – the radius of the sphere for counting the neighbors. Not use if None, Default:None
ord (
int
, optional) – the order of norm to use for distance calculation. Default:2
(Euclidean distance).
- Returns:
The sampled points, with the shape (…, num, D).
- Return type:
output (
torch.Tensor
)
Warning
This operation supports batch operations if
radius
is not given, where the dimension of input points is (…, N, D), otherwise it has to be (N, D). This is because given a radius to remove outliers, the number of output points in each batch can be different.Example
>>> import torch, pypose as pp >>> points = torch.tensor([[0., 0., 0.], ... [1., 0., 0.], ... [0., 1., 0.], ... [0., 1., 1.], ... [10., 1., 1.], ... [10., 1., 10.]]) >>> pp.knn_filter(points, k=2, radius=5) tensor([[0.3333, 0.3333, 0.0000], [0.3333, 0.3333, 0.0000], [0.0000, 0.6667, 0.3333], [0.0000, 0.6667, 0.3333]])