{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Visual image comparison\n\nImage comparison is particularly useful when performing image processing tasks\nsuch as exposure manipulations, filtering, and restoration.\n\nThis example shows how to easily compare two images with various approaches.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nfrom matplotlib.gridspec import GridSpec\n\nimport skimage as ski\n\n\nimg1 = ski.data.coins()\nimg1_equalized = ski.exposure.equalize_hist(img1)\nimg2 = ski.transform.rotate(img1, 2)\n\n\ncomp_equalized = ski.util.compare_images(img1, img1_equalized, method='checkerboard')\ndiff_rotated = ski.util.compare_images(img1, img2, method='diff')\nblend_rotated = ski.util.compare_images(img1, img2, method='blend')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Checkerboard\n\nThe `checkerboard` method alternates tiles from the first and the second\nimages.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig = plt.figure(figsize=(8, 9))\n\ngs = GridSpec(3, 2)\nax0 = fig.add_subplot(gs[0, 0])\nax1 = fig.add_subplot(gs[0, 1])\nax2 = fig.add_subplot(gs[1:, :])\n\nax0.imshow(img1, cmap='gray')\nax0.set_title('Original')\nax1.imshow(img1_equalized, cmap='gray')\nax1.set_title('Equalized')\nax2.imshow(comp_equalized, cmap='gray')\nax2.set_title('Checkerboard comparison')\n\nfor a in (ax0, ax1, ax2):\n    a.set_axis_off()\n\nfig.tight_layout()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Diff\n\nThe `diff` method computes the absolute difference between the two images.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig = plt.figure(figsize=(8, 9))\n\ngs = GridSpec(3, 2)\nax0 = fig.add_subplot(gs[0, 0])\nax1 = fig.add_subplot(gs[0, 1])\nax2 = fig.add_subplot(gs[1:, :])\n\nax0.imshow(img1, cmap='gray')\nax0.set_title('Original')\nax1.imshow(img2, cmap='gray')\nax1.set_title('Rotated')\nax2.imshow(diff_rotated, cmap='gray')\nax2.set_title('Diff comparison')\n\nfor a in (ax0, ax1, ax2):\n    a.set_axis_off()\n\nfig.tight_layout()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Blend\n\n`blend` is the result of the average of the two images.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig = plt.figure(figsize=(8, 9))\n\ngs = GridSpec(3, 2)\nax0 = fig.add_subplot(gs[0, 0])\nax1 = fig.add_subplot(gs[0, 1])\nax2 = fig.add_subplot(gs[1:, :])\n\nax0.imshow(img1, cmap='gray')\nax0.set_title('Original')\nax1.imshow(img2, cmap='gray')\nax1.set_title('Rotated')\nax2.imshow(blend_rotated, cmap='gray')\nax2.set_title('Blend comparison')\n\nfor a in (ax0, ax1, ax2):\n    a.set_axis_off()\n\nfig.tight_layout()\n\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.12"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}