{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# ORB feature detector and binary descriptor\n\nThis example demonstrates the ORB feature detection and binary description\nalgorithm. It uses an oriented FAST detection method and the rotated BRIEF\ndescriptors.\n\nUnlike BRIEF, ORB is comparatively scale and rotation invariant while still\nemploying the very efficient Hamming distance metric for matching. As such, it\nis preferred for real-time applications.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from skimage import data\nfrom skimage import transform\nfrom skimage.feature import match_descriptors, ORB, plot_matched_features\nfrom skimage.color import rgb2gray\nimport matplotlib.pyplot as plt\n\n\nimg1 = rgb2gray(data.astronaut())\nimg2 = transform.rotate(img1, 180)\ntform = transform.AffineTransform(scale=(1.3, 1.1), rotation=0.5, translation=(0, -200))\nimg3 = transform.warp(img1, tform)\n\ndescriptor_extractor = ORB(n_keypoints=200)\n\ndescriptor_extractor.detect_and_extract(img1)\nkeypoints1 = descriptor_extractor.keypoints\ndescriptors1 = descriptor_extractor.descriptors\n\ndescriptor_extractor.detect_and_extract(img2)\nkeypoints2 = descriptor_extractor.keypoints\ndescriptors2 = descriptor_extractor.descriptors\n\ndescriptor_extractor.detect_and_extract(img3)\nkeypoints3 = descriptor_extractor.keypoints\ndescriptors3 = descriptor_extractor.descriptors\n\nmatches12 = match_descriptors(descriptors1, descriptors2, cross_check=True)\nmatches13 = match_descriptors(descriptors1, descriptors3, cross_check=True)\n\nfig, ax = plt.subplots(nrows=2, ncols=1)\n\nplt.gray()\n\nplot_matched_features(\n    img1,\n    img2,\n    keypoints0=keypoints1,\n    keypoints1=keypoints2,\n    matches=matches12,\n    ax=ax[0],\n)\nax[0].axis('off')\nax[0].set_title(\"Original Image vs. Transformed Image\")\n\nplot_matched_features(\n    img1,\n    img3,\n    keypoints0=keypoints1,\n    keypoints1=keypoints3,\n    matches=matches13,\n    ax=ax[1],\n)\nax[1].axis('off')\nax[1].set_title(\"Original Image vs. Transformed Image\")\n\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
}