clustering.py 934 B

1234567891011121314151617181920212223
  1. """Example usage of remove_outliers() and compute_clustering()"""
  2. # Import the vedo library and numpy
  3. from vedo import np, Points, show
  4. # Generate 4 random sets of N points in 3D space
  5. N = 2000
  6. f = 0.6
  7. noise1 = np.random.rand(N, 3) * f + np.array([1, 1, 0])
  8. noise2 = np.random.rand(N, 3) * f + np.array([1, 0, 1.2])
  9. noise3 = np.random.rand(N, 3) * f + np.array([0, 1, 1])
  10. noise4 = np.random.randn(N, 3) * f / 8 + np.array([1, 1, 1])
  11. # Create a Points object from the noisy point sets
  12. noise4 = Points(noise4).remove_outliers(radius=0.05).coordinates
  13. pts = noise1.tolist() + noise2.tolist() + noise3.tolist() + noise4.tolist()
  14. pts = Points(pts)
  15. # Cluster the points to find back their original identity
  16. clpts = pts.compute_clustering(radius=0.1).print()
  17. # Set the color of the points based on their cluster ID using the 'jet' colormap
  18. clpts.cmap("jet", "ClusterId")
  19. show(clpts, __doc__, axes=1, viewup='z', bg='blackboard').close()