siavashk / pycpd

Pure Numpy Implementation of the Coherent Point Drift Algorithm
MIT License
506 stars 114 forks source link

How to export transformed point cloud - non-rigid registration #85

Closed MathieuLatulippe closed 8 months ago

MathieuLatulippe commented 1 year ago

Hi,

First of all, thank you for the great work. I'm currently trying to use your library to perform data fusion of CMM and 3D scanner data (for metrological application). I'm trying to perform non-rigid registration between two point clouds, but I cannot find how to export the transformed source point cloud.

For rigid transformation, I understand the example:

# create a RigidRegistration object
reg = RigidRegistration(X=target, Y=source)
# run the registration & collect the results
TY, (s_reg, R_reg, t_reg) = reg.register()

where the transformed point cloud and the transformation matrices are in TY, (s_reg, R_reg, t_reg) = reg.register()

But how do you get those for DeformableRegistration?

Thank you!

PS: I know this is not a feature request, but I don't know where to post my question.

gattia commented 1 year ago

All of the registration classes return the same thing when running .register():TY, reg_params = reg.register(x, y)Your transformed source points are TY and reg_params is a tuple of the registration parameters. Hope that helps. Sent from my iPhoneOn May 3, 2023, at 9:54 AM, MathieuLatulippe @.***> wrote: Hi, First of all, thank you for the great work. I'm currently trying to use your library to perform data fusion of CMM and 3D scanner data (for metrological application). I'm trying to perform non-rigid registration between two point clouds, but I cannot find how to export the transformed source point cloud. For rigid transformation, I understand the example:

create a RigidRegistration object

reg = RigidRegistration(X=target, Y=source)

run the registration & collect the results

TY, (s_reg, R_reg, t_reg) = reg.register()

where the transformed point cloud and the transformation matrices are in TY, (s_reg, R_reg, t_reg) = reg.register() But how do you get those for DeformableRegistration? Thank you! PS: I know this is not a feature request, but I don't know where to post my question.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

fengyasi commented 8 months ago

Hi, when I use the DeformableRegistration, _it appears the value error: ValueError: The target point cloud (X) must be at a 2D numpy array._Here is code:

from pycpd import RigidRegistration
import numpy as np
from glob import glob
import trimesh
from pycpd import DeformableRegistration

LANDMARK_DIR = "D:\PengChen\ssmaaa"
landmark_files = glob(LANDMARK_DIR + "/*.stl")

def compute_centroid(data):
    return np.mean(data, axis=0)

# 定义函数计算质心到给定点的向量
def compute_vector(point, centroid):
    return point - centroid

first_mesh = trimesh.load_mesh(landmark_files[0])
second_mesh = trimesh.load_mesh(landmark_files[1])
first_vertices = first_mesh.vertices
first_faces = first_mesh.faces

second_vertices = second_mesh.vertices
centroid = compute_centroid(first_vertices)

reg = DeformableRegistration(X=second_vertices, Y=first_vertices)

TY, (s_reg, R_reg, t_reg) = reg.register()

# TY is the transformed source points
# the values in () are the registration parameters.
# In this case of rigid registration they are:
#     s_reg the scale of the registration
#     R_reg the rotation matrix of the registration
#     t_reg the translation of the registration
gattia commented 8 months ago

Check the dimensions of your numpy arrays input into the registration. I assume they are either 1 or >2 dimensions. They should be MxN in shape where M is the number of points you have and N is the dimension of the data.

mom assuming the original question is answered and I am closing this issue.

thanks,

anthony