{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using Special Ops" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook dives into some technical details of the ImageJ Ops library.\n", "\n", "It is recommended that you first read and understand the ImageJ Ops notebook before tackling this one." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Added new repo: imagej.public\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2e223d23-b953-4e6f-8db7-3c5a0b5687ec", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "2.0.0-rc-71" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%classpath config resolver imagej.public \"https://maven.imagej.net/content/groups/public\"\n", "%classpath add mvn net.imagej imagej 2.0.0-rc-71\n", "ij = new net.imagej.ImageJ()\n", "ij.getVersion()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This tutorial covers the so-called `SPECIAL` ops. Every special op produces one primary output from some fixed number of primary inputs. The number of such inputs for a given op is known as its `ARITY`. The framework provides interfaces for three arities:\n", "* 1 input = UNARY e.g.: eight = math.sqrt(64)\n", "* 2 inputs = BINARY e.g.: eight = math.add(3, 5)\n", "* 0 inputs = NULLARY e.g.: zero = math.zero()\n", "Additional arities (e.g., ternary) are feasible, but not implemented.\n", "\n", "The `SPECIAL` ops can be classified into three main categories: `COMPUTER`, `FUNCTION` and `INPLACE`:\n", "* `COMPUTER`: An op which will write its result to pre-allocated output, i.e. an empty (zero) image\n", "* `FUNCTION`: An op which will allocate on its own and then return it\n", "* `INPLACE`: An op which will write its output to one of the input arguments, hence mutating one of the inputs\n", "\n", "Special ops may also have any number of additional secondary inputs, which do not affect the arity of the op. More on that below.\n", "\n", "Let's try some example op calls, to illustrate the difference between these various kinds of special ops.\n", "\n", "First, we will create some test images to work with. In order to do that, we define and use a helper function, which creates an image of specified width and height using the `create.img` op, and then populates the contents of that image using the `image.equation` op, which sets the value of each sample according to a specified formula. In this case, we create four images depicting different patterns based on the location of a sample, which may be accessed via the variable `p[]` inside the formula." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Created image: Sinusoid of size [150,150]\n", "Created image: Gradient of size [150,150]\n", "Created image: Circle of size [150,150]\n", "Created image: Diamond of size [150,150]\n" ] }, { "data": { "text/html": [ "
sinusoid | gradient | spot | cross |
---|---|---|---|