{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\nTV-L1 vs iLK\n============\n\nComparison the TV-L1 and iLK methods for the optical flow estimation.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from time import time\nimport matplotlib.pyplot as plt\nimport pyimof\n\n\nseq_list = pyimof.data.__all__\nseq_count = len(seq_list)\n\nfig = plt.figure(figsize=((9, 2*seq_count)))\nax_array = fig.subplots(seq_count, 3)\nax_array[0, 0].set_title(\"Reference image\")\nax_array[0, 1].set_title(\"TV-L1 result\")\nax_array[0, 2].set_title(\"iLK result\")\n\n# --- Loop over available sequences\n\nfor name, (ax0, ax1, ax2) in zip(seq_list, ax_array):\n\n    title = name.capitalize()\n\n    print(f\"Processing the {title} sequence\")\n\n    # --- Load data\n    I0, I1 = pyimof.data.__dict__[name]()\n\n    ax0.imshow(I0, cmap='gray')\n    ax0.set_ylabel(title)\n    ax0.set_xticks([])\n    ax0.set_yticks([])\n\n    # --- Run TV-L1\n\n    t0 = time()\n    u, v = pyimof.solvers.tvl1(I0, I1)\n    t1 = time()\n\n    pyimof.display.plot(u, v, ax=ax1, colorwheel=False)\n\n    print(\"\\tTV-L1 processing time: {:02f}sec\".format(t1-t0))\n\n    # --- Run iLK\n\n    t0 = time()\n    u, v = pyimof.solvers.ilk(I0, I1)\n    t1 = time()\n\n    pyimof.display.plot(u, v, ax=ax2, colorwheel=False)\n\n    print(\"\\tILK processing time: {:02f}sec\".format(t1-t0))\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.7.3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}