.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/registration/plot_karateka.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_registration_plot_karateka.py: Intrinsic vs Extrinsic deformation ================================== Intrinsic and extrinsic deformations are two different approaches to non-rigid deformation. This example shows how both approaches differ on a simple 2D example. .. GENERATED FROM PYTHON SOURCE LINES 10-33 .. code-block:: Python import sys import pykeops from utils_karateka import ( load_data, plot_extrinsic_deformation, plot_intrinsic_deformation, plot_karatekas, ) import skshapes as sks sys.path.append(pykeops.get_build_folder()) kwargs = { "loss": sks.L2Loss(), "optimizer": sks.LBFGS(), "n_iter": 5, "gpu": False, "verbose": True, } .. GENERATED FROM PYTHON SOURCE LINES 34-35 Load the data .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python source, target = load_data() plot_karatekas() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /auto_examples/registration/images/sphx_glr_plot_karateka_001.png :alt: plot karateka :srcset: /auto_examples/registration/images/sphx_glr_plot_karateka_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/runner/work/scikit-shapes/scikit-shapes/doc/source/auto_examples/registration/images/sphx_glr_plot_karateka_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 41-48 Extrinsic deformation --------------------- Extrinsic deformation is a kind of deformation that relies on the deformation of the ambient space, which is transferred to the shape. Intituively, you can think that you are twisting a sheet of paper on which the shape is drawn. .. GENERATED FROM PYTHON SOURCE LINES 48-64 .. code-block:: Python source.control_points = source.bounding_grid(N=10, offset=0.05) model = sks.ExtrinsicDeformation( n_steps=6, kernel="gaussian", scale=1.0, control_points=True, ) registration = sks.Registration( model=model, regularization_weight=0.1, **kwargs ) registration.fit(source=source, target=target) .. rst-class:: sphx-glr-script-out .. code-block:: none Initial loss : 5.37e+01 = 5.37e+01 + 0.1 * 0.00e+00 (fidelity + regularization_weight * regularization) Loss after 1 iteration(s) : 3.42e+00 = 7.02e-01 + 0.1 * 2.72e+01 (fidelity + regularization_weight * regularization) Loss after 2 iteration(s) : 2.72e+00 = 1.30e-01 + 0.1 * 2.59e+01 (fidelity + regularization_weight * regularization) Loss after 3 iteration(s) : 2.44e+00 = 8.35e-02 + 0.1 * 2.36e+01 (fidelity + regularization_weight * regularization) Loss after 4 iteration(s) : 2.23e+00 = 6.60e-02 + 0.1 * 2.16e+01 (fidelity + regularization_weight * regularization) Loss after 5 iteration(s) : 2.09e+00 = 4.59e-02 + 0.1 * 2.05e+01 (fidelity + regularization_weight * regularization) .. GENERATED FROM PYTHON SOURCE LINES 65-66 Visualize the deformation .. GENERATED FROM PYTHON SOURCE LINES 68-72 .. code-block:: Python plot_extrinsic_deformation( source=source, target=target, registration=registration, animation=True ) .. image-sg:: /auto_examples/registration/images/sphx_glr_plot_karateka_002.gif :alt: plot karateka :srcset: /auto_examples/registration/images/sphx_glr_plot_karateka_002.gif :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 73-83 Intrinsic deformation --------------------- An intrinsic deformation is a deformation that is not transferable from one shape to another. It is defined as a sequence of small displacements of the points of the shape. In this setting, you can think of the shape as a puppet that you can deform thanks to a set of strings attached to its vertices. In this example, we use the "as isometric as possible" metric, which tries to preserve the lengths of the edges of the shape. .. GENERATED FROM PYTHON SOURCE LINES 83-97 .. code-block:: Python model = sks.IntrinsicDeformation( n_steps=8, metric="as_isometric_as_possible", ) registration = sks.Registration( model=model, regularization_weight=500, **kwargs ) registration.fit(source=source, target=target) .. rst-class:: sphx-glr-script-out .. code-block:: none Initial loss : 5.37e+01 = 5.37e+01 + 500 * 0.00e+00 (fidelity + regularization_weight * regularization) Loss after 1 iteration(s) : 6.99e+00 = 4.08e+00 + 500 * 5.81e-03 (fidelity + regularization_weight * regularization) Loss after 2 iteration(s) : 6.26e+00 = 2.43e+00 + 500 * 7.65e-03 (fidelity + regularization_weight * regularization) Loss after 3 iteration(s) : 6.02e+00 = 2.12e+00 + 500 * 7.81e-03 (fidelity + regularization_weight * regularization) Loss after 4 iteration(s) : 6.02e+00 = 2.10e+00 + 500 * 7.84e-03 (fidelity + regularization_weight * regularization) Loss after 5 iteration(s) : 6.02e+00 = 2.10e+00 + 500 * 7.83e-03 (fidelity + regularization_weight * regularization) .. GENERATED FROM PYTHON SOURCE LINES 98-99 Visualize the deformation .. GENERATED FROM PYTHON SOURCE LINES 99-103 .. code-block:: Python plot_intrinsic_deformation( source=source, target=target, registration=registration, animation=True ) .. image-sg:: /auto_examples/registration/images/sphx_glr_plot_karateka_003.gif :alt: plot karateka :srcset: /auto_examples/registration/images/sphx_glr_plot_karateka_003.gif :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 16.547 seconds) .. _sphx_glr_download_auto_examples_registration_plot_karateka.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_karateka.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_karateka.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_