.. 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 :ref:`Go to the end ` 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:: Python # Authors: Guillaume Auzias # License: MIT # sphinx_gallery_thumbnail_number = 2 .. GENERATED FROM PYTHON SOURCE LINES 15-19 NOTE: there is no visualization tool in slam, but we provide at the end of this script exemplare code to do the visualization with an external solution ############################################################################## .. GENERATED FROM PYTHON SOURCE LINES 21-22 importation of slam modules .. GENERATED FROM PYTHON SOURCE LINES 22-25 .. code-block:: Python import slam.io as sio import trimesh .. GENERATED FROM PYTHON SOURCE LINES 26-27 loading an two unregistered meshes .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: Python 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 31-33 compute ICP registration this functionnality requires to install the optional package rtree .. GENERATED FROM PYTHON SOURCE LINES 33-39 .. code-block:: Python 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 .. code-block:: none [[-0.59600058 -0.08030801 0.79895803 62.68024381] [ 0.08460222 0.98316811 0.16193497 53.44798153] [-0.79851473 0.16410696 -0.57917452 49.63045684] [ 0. 0. 0. 1. ]] 0.006486115641526297 .. GENERATED FROM PYTHON SOURCE LINES 40-41 apply the estimated rigid transformation to the mesh .. GENERATED FROM PYTHON SOURCE LINES 41-43 .. code-block:: Python mesh_1.apply_transform(transf_mat) .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 44-65 VISUALIZATION USING EXTERNAL TOOLS ############################################################################ # Visualization with visbrain import slam.plot as splt import numpy as np ############################################################################### # plot them to check the misalignment 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() ############################################################################### # plot the two meshes to check they are now aligned joint_mesh = mesh_1 + mesh_2 visb_sc = splt.visbrain_plot( mesh=joint_mesh, tex=joint_tex, caption="after registration" ) visb_sc.preview() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.219 seconds) .. _sphx_glr_download_auto_examples_example_registration.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_registration.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_registration.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_registration.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_