.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/MeshModification/demo_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_examples_MeshModification_demo_registration.py: Registration ============ This example illustrates registration of meshes and images using the Stanford Bunny. .. GENERATED FROM PYTHON SOURCE LINES 10-15 .. code-block:: Python import mymesh from mymesh import register import numpy as np import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 16-31 .. code-block:: Python bunny1 = mymesh.demo_mesh('bunny') bunny2 = mymesh.demo_mesh('bunny-res2') # Perform an arbitrary rotation to bunny2 so that they are mis-aligned bunny2 = bunny2.Transform([np.pi/6, -np.pi/6, np.pi/6], transformation='rotation', InPlace=True) # Plot overlap of bunny1 and bunny2 def overlap_plot(m1, m2): m1.NodeData['label'] = np.zeros(m1.NNode) m2.NodeData['label'] = np.ones(m2.NNode) overlap = m1.copy() overlap.merge(m2) overlap.plot(scalars='label', show_colorbar=False, view='xy') overlap_plot(bunny1, bunny2) .. image-sg:: /examples/MeshModification/images/sphx_glr_demo_registration_001.png :alt: demo registration :srcset: /examples/MeshModification/images/sphx_glr_demo_registration_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none RFBOutputContext() Identifying mesh nodes...Done .. GENERATED FROM PYTHON SOURCE LINES 32-46 .. code-block:: Python bunny_img1 = mymesh.demo_image('bunny') threshold = 100 voxelsize = (0.337891, 0.337891, 0.5) # mm # Perform an arbitrary rotation to make a mis-aligned copy the image R = register.rotation([np.pi/6, -np.pi/6, np.pi/6], center=np.array(bunny_img1.shape)/2) bunny_img2 = register.transform_image(bunny_img1, R) # Plot overlap of bunny1_img and bunny2_img # (purple=img1, orange=img2, pale yellow=overlap) overlay = register.ImageOverlay(bunny_img1, bunny_img2, threshold=threshold) plt.imshow(overlay[:,250], cmap='inferno') plt.axis('off') .. image-sg:: /examples/MeshModification/images/sphx_glr_demo_registration_002.png :alt: demo registration :srcset: /examples/MeshModification/images/sphx_glr_demo_registration_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 47-51 Mesh-to-Mesh Registration ------------------------- Align the two meshes using the iterative closest point (ICP) algorithm .. GENERATED FROM PYTHON SOURCE LINES 51-56 .. code-block:: Python bunny_aligned, T = register.Mesh2Mesh(bunny1, bunny2) # Plot overlap_plot(bunny1, bunny_aligned) .. image-sg:: /examples/MeshModification/images/sphx_glr_demo_registration_003.png :alt: demo registration :srcset: /examples/MeshModification/images/sphx_glr_demo_registration_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none RFBOutputContext() Identifying mesh nodes...Done .. GENERATED FROM PYTHON SOURCE LINES 57-60 Image-to-Image Registration --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 60-70 .. code-block:: Python # Align the two images using the iterative closest point (ICP) algorithm img_aligned, T = register.Image2Image(bunny_img1, bunny_img2, method='icp', threshold=threshold, scale=0.5) # Plot overlap # (purple=img1, orange=img2, pale yellow=overlap) overlay = register.ImageOverlay(bunny_img1, img_aligned, threshold=threshold) plt.imshow(overlay[:,250], cmap='inferno') plt.axis('off') .. image-sg:: /examples/MeshModification/images/sphx_glr_demo_registration_004.png :alt: demo registration :srcset: /examples/MeshModification/images/sphx_glr_demo_registration_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 22.251 seconds) .. _sphx_glr_download_examples_MeshModification_demo_registration.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_registration.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_registration.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_registration.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_