.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/example_registration.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_example_registration.py: .. _example_registration: =================================== Show mesh registration features in slam =================================== .. GENERATED FROM PYTHON SOURCE LINES 8-14 .. code-block:: default # Authors: Guillaume Auzias # License: BSD (3-clause) # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 15-16 importation of slam modules .. GENERATED FROM PYTHON SOURCE LINES 16-21 .. code-block:: default import slam.plot as splt import slam.io as sio import numpy as np import trimesh .. GENERATED FROM PYTHON SOURCE LINES 22-23 loading an two unregistered meshes .. GENERATED FROM PYTHON SOURCE LINES 23-26 .. code-block:: default mesh_1 = sio.load_mesh("../examples/data/example_mesh.gii") mesh_2 = sio.load_mesh("../examples/data/example_mesh_2.gii") .. GENERATED FROM PYTHON SOURCE LINES 27-28 plot them to check the misalignment .. GENERATED FROM PYTHON SOURCE LINES 28-36 .. code-block:: default joint_mesh = mesh_1 + mesh_2 joint_tex = np.ones((joint_mesh.vertices.shape[0],)) joint_tex[: mesh_1.vertices.shape[0]] = 10 visb_sc = splt.visbrain_plot( mesh=joint_mesh, tex=joint_tex, caption="before registration" ) visb_sc.preview() .. image:: /auto_examples/images/sphx_glr_example_registration_001.png :alt: example registration :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 37-39 compute ICP registration this functionnality requires to install the optional package rtree .. GENERATED FROM PYTHON SOURCE LINES 39-45 .. code-block:: default transf_mat, cost = trimesh.registration.mesh_other( mesh_1, mesh_2, samples=500, scale=False, icp_first=10, icp_final=100 ) print(transf_mat) print(cost) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none [[-0.59202764 -0.09421463 0.8003917 62.85878541] [ 0.09168714 0.97882135 0.18303614 53.43305704] [-0.80068517 0.18174808 -0.57085103 49.62517482] [ 0. 0. 0. 1. ]] 0.006163062935171203 .. GENERATED FROM PYTHON SOURCE LINES 46-47 apply the estimated rigid transformation to the mesh .. GENERATED FROM PYTHON SOURCE LINES 47-49 .. code-block:: default mesh_1.apply_transform(transf_mat) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 50-51 plot the two meshes to check they are now aligned .. GENERATED FROM PYTHON SOURCE LINES 51-56 .. code-block:: default joint_mesh = mesh_1 + mesh_2 visb_sc = splt.visbrain_plot( mesh=joint_mesh, tex=joint_tex, caption="after registration" ) visb_sc.preview() .. image:: /auto_examples/images/sphx_glr_example_registration_002.png :alt: example registration :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 8.256 seconds) .. _sphx_glr_download_auto_examples_example_registration.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_registration.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_registration.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_