.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/applications/plot_image_comparison.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. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_applications_plot_image_comparison.py: ======================= Visual image comparison ======================= Image comparison is particularly useful when performing image processing tasks such as exposure manipulations, filtering, and restoration. This example shows how to easily compare two images with various approaches. .. GENERATED FROM PYTHON SOURCE LINES 12-29 .. code-block:: Python import matplotlib.pyplot as plt from matplotlib.gridspec import GridSpec import skimage as ski img1 = ski.data.coins() img1_equalized = ski.exposure.equalize_hist(img1) img2 = ski.transform.rotate(img1, 2) comp_equalized = ski.util.compare_images(img1, img1_equalized, method='checkerboard') diff_rotated = ski.util.compare_images(img1, img2, method='diff') blend_rotated = ski.util.compare_images(img1, img2, method='blend') .. GENERATED FROM PYTHON SOURCE LINES 30-35 Checkerboard ============ The `checkerboard` method alternates tiles from the first and the second images. .. GENERATED FROM PYTHON SOURCE LINES 35-56 .. code-block:: Python fig = plt.figure(figsize=(8, 9)) gs = GridSpec(3, 2) ax0 = fig.add_subplot(gs[0, 0]) ax1 = fig.add_subplot(gs[0, 1]) ax2 = fig.add_subplot(gs[1:, :]) ax0.imshow(img1, cmap='gray') ax0.set_title('Original') ax1.imshow(img1_equalized, cmap='gray') ax1.set_title('Equalized') ax2.imshow(comp_equalized, cmap='gray') ax2.set_title('Checkerboard comparison') for a in (ax0, ax1, ax2): a.set_axis_off() fig.tight_layout() .. image-sg:: /auto_examples/applications/images/sphx_glr_plot_image_comparison_001.png :alt: Original, Equalized, Checkerboard comparison :srcset: /auto_examples/applications/images/sphx_glr_plot_image_comparison_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 57-61 Diff ==== The `diff` method computes the absolute difference between the two images. .. GENERATED FROM PYTHON SOURCE LINES 61-82 .. code-block:: Python fig = plt.figure(figsize=(8, 9)) gs = GridSpec(3, 2) ax0 = fig.add_subplot(gs[0, 0]) ax1 = fig.add_subplot(gs[0, 1]) ax2 = fig.add_subplot(gs[1:, :]) ax0.imshow(img1, cmap='gray') ax0.set_title('Original') ax1.imshow(img2, cmap='gray') ax1.set_title('Rotated') ax2.imshow(diff_rotated, cmap='gray') ax2.set_title('Diff comparison') for a in (ax0, ax1, ax2): a.set_axis_off() fig.tight_layout() .. image-sg:: /auto_examples/applications/images/sphx_glr_plot_image_comparison_002.png :alt: Original, Rotated, Diff comparison :srcset: /auto_examples/applications/images/sphx_glr_plot_image_comparison_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 83-87 Blend ===== `blend` is the result of the average of the two images. .. GENERATED FROM PYTHON SOURCE LINES 87-108 .. code-block:: Python fig = plt.figure(figsize=(8, 9)) gs = GridSpec(3, 2) ax0 = fig.add_subplot(gs[0, 0]) ax1 = fig.add_subplot(gs[0, 1]) ax2 = fig.add_subplot(gs[1:, :]) ax0.imshow(img1, cmap='gray') ax0.set_title('Original') ax1.imshow(img2, cmap='gray') ax1.set_title('Rotated') ax2.imshow(blend_rotated, cmap='gray') ax2.set_title('Blend comparison') for a in (ax0, ax1, ax2): a.set_axis_off() fig.tight_layout() plt.show() .. image-sg:: /auto_examples/applications/images/sphx_glr_plot_image_comparison_003.png :alt: Original, Rotated, Blend comparison :srcset: /auto_examples/applications/images/sphx_glr_plot_image_comparison_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.118 seconds) .. _sphx_glr_download_auto_examples_applications_plot_image_comparison.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-image/scikit-image/main?filepath=notebooks/auto_examples/applications/plot_image_comparison.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_image_comparison.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_image_comparison.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_image_comparison.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_