Grouping inliers or outliers of point clouds using a voronoi diagram and the connectivity node.
- Build a voronoi diagram
- Remove long connections
- Classify by connectivity
- Group islands based on points per class
Added an example file (outlier_removal_python_snippet.hip) containing a Python Snippet Geometry Node for removing outliers based on the Mahalanobis distance using NumPy.
import hou
import numpy as np
geo = kwargs['inputs'][0].freeze()
points = np.array([p.position() for p in geo.points()])
if len(points) > 3:
mean = np.mean(points, axis=0)
cov = np.cov(points, rowvar=False)
inv_cov = np.linalg.inv(cov + np.eye(3) * 1e-6)
diff = points - mean
mahal = np.sqrt(np.sum(np.dot(diff, inv_cov) * diff, axis=1))
geo.addAttrib(hou.attribType.Point, "mahal", 0.0)
for i, p in enumerate(geo.points()):
p.setAttribValue("mahal", float(mahal[i]))
return geo