siavashk / pycpd

Pure Numpy Implementation of the Coherent Point Drift Algorithm
MIT License
510 stars 115 forks source link

Deformable Registration on downsampled point cloud cannot be applied on original point cloud with different size #86

Closed AkeelMedina22 closed 1 year ago

AkeelMedina22 commented 1 year ago

Describe the bug When using DeformableRegistration and registering on a downsampled point cloud, I want to apply the registration parameters on the much larger, original point cloud. This works for Rigid and Affine registration, but not for Deformable.

To Reproduce

def cpd(target_pcd, source_pcd, downsample):
    down_t = o3d.geometry.PointCloud()
    down_s = o3d.geometry.PointCloud()

    down_t.points = o3d.utility.Vector3dVector(np.asarray(target_pcd.points)[np.random.randint(len(np.asarray(target_pcd.points)), size=downsample)][:,:])
    down_s.points = o3d.utility.Vector3dVector(np.asarray(source_pcd.points)[np.random.randint(len(np.asarray(source_pcd.points)), size=downsample)][:,:])

    reg = DeformableRegistration(X=np.asarray(
        down_t.points), Y=np.asarray(down_s.points))

    reg.register()

    points = reg.transform_point_cloud(Y=np.asarray(source_pcd.points))

    deformed_pcd = o3d.geometry.PointCloud()
    deformed_pcd.points = o3d.utility.Vector3dVector(points[:, 0:3])
    return deformed_pcd

And the error is:

line 68, in transform_point_cloud
    return Y + np.dot(self.G, self.W)
ValueError: operands could not be broadcast together with shapes (155201,3) (2500,3)

It says in the comments of the source code "Best for predicting on new points not used to run initial registration", so how can I do this? Any advice for now would be appreciated.

gattia commented 1 year ago

Below link is a link to an example that uses deformable registration on a subset of the points.

If you’ve installed using pip it might be that pop doesn’t have the latest version. Try installing from source.

https://github.com/siavashk/pycpd/blob/master/examples/fish_deformable_3D_register_with_subset_of_points.py

AkeelMedina22 commented 1 year ago

This worked, thanks!