Point Cloud Metrics
Point Cloud Utils has functions to compute a number of commonly used metrics between point clouds.
Chamfer Distance
The Chamfer distance between two point clouds
The following code computes the Chamfer distance between two point clouds:
import point_cloud_utils as pcu
# p1 is an (n, 3)-shaped numpy array containing one point per row
p1 = pcu.load_mesh_v("point_cloud_1.ply")
# p2 is an (m, 3)-shaped numpy array containing one point per row
p2 = pcu.load_mesh_v("point_cloud_2.ply")
# Compute the chamfer distance between p1 and p2
cd = pcu.chamfer_distance(p1, p2)
Hausdorff distance
The Hausdorff distance between two point clouds
The following code computes the Hausdorff distance between two point clouds:
import point_cloud_utils as pcu
# p1 is an (n, 3)-shaped numpy array containing one point per row
p1 = pcu.load_mesh_v("point_cloud_1.ply")
# p2 is an (m, 3)-shaped numpy array containing one point per row
p2 = pcu.load_mesh_v("point_cloud_2.ply")
# Compute the chamfer distance between p1 and p2
hd = pcu.hausdorff_distance(p1, p2)
One sided Hausdorff distance
In some applications, one only needs the one-sided Hausdorff distance between
The following code computes the one-sided Hausdorff distance between two point clouds:
import point_cloud_utils as pcu
# p1 is an (n, 3)-shaped numpy array containing one point per row
p1 = pcu.load_mesh_v("point_cloud_1.ply")
# p2 is an (m, 3)-shaped numpy array containing one point per row
p2 = pcu.load_mesh_v("point_cloud_2.ply")
# Compute the chamfer distance between p1 and p2
hd_p1_to_p2 = pcu.one_sided_hausdorff_distance(p1, p2)
Note
To get the pcu.one_sided_hausdorff_distance
Earth-Mover's (Sinkhorn) distance
The Earth Mover's distance between two point clouds
Point Cloud Utils implements the sinkhorn algorithm for computing the (approximate) Earth Mover's Distance. To compute the EMD, run:
import point_cloud_utils as pcu
# p1 is an (n, 3)-shaped numpy array containing one point per row
p1 = pcu.load_mesh_v("point_cloud_1.ply")
# p2 is an (m, 3)-shaped numpy array containing one point per row
p2 = pcu.load_mesh_v("point_cloud_2.ply")
# Compute the chamfer distance between p1 and p2
emd, pi = pcu.earth_movers_distance(p1, p2)