|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# deeptrack.elementwise\n", |
| 8 | + "\n", |
| 9 | + "<a href=\"https://colab.research.google.com/github/DeepTrackAI/DeepTrack2/blob/develop/tutorials/3-advanced-topics/DTAT389_elementwise.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "code", |
| 14 | + "execution_count": 1, |
| 15 | + "metadata": {}, |
| 16 | + "outputs": [], |
| 17 | + "source": [ |
| 18 | + "# !pip install deeptrack # Uncomment if running on Colab/Kaggle." |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "markdown", |
| 23 | + "metadata": {}, |
| 24 | + "source": [ |
| 25 | + "This advanced tutorial introduces the elementwise module." |
| 26 | + ] |
| 27 | + }, |
| 28 | + { |
| 29 | + "cell_type": "markdown", |
| 30 | + "metadata": {}, |
| 31 | + "source": [ |
| 32 | + "## 1. What is elementwise?\n", |
| 33 | + "\n", |
| 34 | + "The elementwise module introduces utility functions which lets the user apply Numpy functions to `Feature` objects elementwise.\n", |
| 35 | + "Some functions included in elementwise are:\n", |
| 36 | + "\n", |
| 37 | + "- Trigonometric\n", |
| 38 | + "- Hyperbolic\n", |
| 39 | + "- Rounding \n", |
| 40 | + "- Exponents and Logarithms\n", |
| 41 | + "- Complex " |
| 42 | + ] |
| 43 | + }, |
| 44 | + { |
| 45 | + "cell_type": "markdown", |
| 46 | + "metadata": {}, |
| 47 | + "source": [ |
| 48 | + "## 2. Initialize a `Feature`\n", |
| 49 | + "\n", |
| 50 | + "We create a feature that subtracts values from an image." |
| 51 | + ] |
| 52 | + }, |
| 53 | + { |
| 54 | + "cell_type": "code", |
| 55 | + "execution_count": null, |
| 56 | + "metadata": {}, |
| 57 | + "outputs": [ |
| 58 | + { |
| 59 | + "name": "stdout", |
| 60 | + "output_type": "stream", |
| 61 | + "text": [ |
| 62 | + "[-9 -8 -7]\n" |
| 63 | + ] |
| 64 | + } |
| 65 | + ], |
| 66 | + "source": [ |
| 67 | + "import numpy as np\n", |
| 68 | + "from deeptrack.features import Feature\n", |
| 69 | + "\n", |
| 70 | + "\n", |
| 71 | + "class Subtract(Feature):\n", |
| 72 | + " def get(self, image, value, **kwargs):\n", |
| 73 | + " return image - value\n", |
| 74 | + "\n", |
| 75 | + "subtract_10 = Subtract(value=10)\n", |
| 76 | + "\n", |
| 77 | + "input_image = np.array([1, 2, 3])\n", |
| 78 | + "output_image = subtract_10(input_image)\n", |
| 79 | + "print(output_image)" |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "cell_type": "markdown", |
| 84 | + "metadata": {}, |
| 85 | + "source": [ |
| 86 | + "## 3. Compute the Absolute value of the feature (In sequence)\n" |
| 87 | + ] |
| 88 | + }, |
| 89 | + { |
| 90 | + "cell_type": "code", |
| 91 | + "execution_count": null, |
| 92 | + "metadata": {}, |
| 93 | + "outputs": [ |
| 94 | + { |
| 95 | + "name": "stdout", |
| 96 | + "output_type": "stream", |
| 97 | + "text": [ |
| 98 | + "[9 8 7]\n", |
| 99 | + "[9 8 7]\n" |
| 100 | + ] |
| 101 | + } |
| 102 | + ], |
| 103 | + "source": [ |
| 104 | + "from deeptrack.elementwise import Abs\n", |
| 105 | + "\n", |
| 106 | + "\n", |
| 107 | + "# Sequentially take the absolute value after subtraction.\n", |
| 108 | + "pipeline = Abs(subtract_10)\n", |
| 109 | + "output_image = pipeline(input_image)\n", |
| 110 | + "print(output_image)\n", |
| 111 | + "\n", |
| 112 | + "# Or equivalently:\n", |
| 113 | + "pipeline = subtract_10 >> Abs()\n", |
| 114 | + "output_image = pipeline(input_image)\n", |
| 115 | + "print(output_image)" |
| 116 | + ] |
| 117 | + } |
| 118 | + ], |
| 119 | + "metadata": { |
| 120 | + "kernelspec": { |
| 121 | + "display_name": "Python 3", |
| 122 | + "language": "python", |
| 123 | + "name": "python3" |
| 124 | + }, |
| 125 | + "language_info": { |
| 126 | + "codemirror_mode": { |
| 127 | + "name": "ipython", |
| 128 | + "version": 3 |
| 129 | + }, |
| 130 | + "file_extension": ".py", |
| 131 | + "mimetype": "text/x-python", |
| 132 | + "name": "python", |
| 133 | + "nbconvert_exporter": "python", |
| 134 | + "pygments_lexer": "ipython3", |
| 135 | + "version": "3.9.13" |
| 136 | + } |
| 137 | + }, |
| 138 | + "nbformat": 4, |
| 139 | + "nbformat_minor": 2 |
| 140 | +} |
0 commit comments