{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## PermuteCoordinatesInverseView Op" ] }, { "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": "78b8ce2b-9867-4f44-9611-0864610c49a1", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "net.imagej.ImageJ@4248b215" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "//load ImageJ\n", "%classpath config resolver imagej.public https://maven.imagej.net/content/groups/public\n", "%classpath add mvn net.imagej imagej 2.0.0-rc-67\n", "\n", "//create ImageJ object\n", "ij = new net.imagej.ImageJ()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This `Op` wraps the `Views.permuteCoordinatesInverse()` method of ImgLib2, performing a [bijective permutation](https://en.wikipedia.org/wiki/Bijection) on the coordinates of any `RandomAccessibleInterval`. This `Op` is the inverse of [`permuteCoordinatesView`](permuteCoordinatesView.ipynb), meaning that it can undo the permutation caused by `permuteCoordinatesView`. Let's see how this `Op` is called:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Available operations:\n", "\t(IntervalView out) =\n", "\tnet.imagej.ops.transform.permuteCoordinatesInverseView.DefaultPermuteCoordinatesInverseView(\n", "\t\tRandomAccessibleInterval in,\n", "\t\tint[] permutation)\n", "\t(IntervalView out) =\n", "\tnet.imagej.ops.transform.permuteCoordinatesInverseView.PermuteCoordinateInverseViewOfDimension(\n", "\t\tRandomAccessibleInterval in,\n", "\t\tint[] permutation,\n", "\t\tint d)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ij.op().help('permuteCoordinatesInverseView')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's look at the parameters of the `Op`:\n", "\n", "* `RandomAccessibleInterval in`: the input image\n", "* `int[] permutation`: an array defining a mapping of coordinates. The mapping is defined as follows: if `i` is any given column/row in an image, then `i` is mapped to `permutation[i]`. So if we have an `Img` of size `[5, 5]` and `permutation = [4, 3, 2, 1, 0]`, then column and row 0 are mapped to 4, column and row 1 are mapped to 3, and so on. However if `permutation = [1, 1, 1, 1, 1]` (which is in fact allowed by `permuteCoordinatesView`, then column and row 0 are mapped to 1, then column and row 1 are mapped to 1, then column and row 2 are mapped to 1, and so on, matching all of the columns to the 2nd column in the `in`. This is not particularly useful, but it is something to be noted. Note that the array **must** be **equal in size** to the dimensions that are to be permuted, as determined by the value (or absence) of `d`.\n", "* `int d`: an **optional** parameter telling the `Op` which dimension to perform the permutation in. If parameter is not passed through then the `Op` will attempt to permute all of the dimensions." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[INFO] Verifying GIF format\n", "[INFO] Reading dimensions\n", "[INFO] Reading data blocks\n" ] }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAnklEQVR42u2WXQrAIAyD48k9mkfbmFAoA39qqx2sQh4ln9hEcRkuAFWiPdYApZQACAAfAEpAzrkqAP4F8Bi6AZChGwCZugBw0+MAZOpyBdz8eAr4aV3+Az0Td4ClQV4FsIJQAXDR8L01ep6hyf9IM2mAtoS0V2HShAHwGYDZwdsKIIUwTcFKMkQArbLpyaSIUkqi9pNAwKr1Ro3YmosbRJ9MlGVXVHcAAAAASUVORK5CYII=" }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "input = ij.scifio().datasetIO().open(\"http://imagej.net/images/ij-icon.gif\")\n", "\n", "ij.notebook().display(input)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's say we have a [permuted](permuteCoordinatesView.ipynb) image that we did some work on:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAoUlEQVR42u2XYQrAIAiF7eQdraM1JjOa5TYIdZDCI+hH7yPTCmoXAICyDOAApZQACAAfAKqAnDMqAPYCOA3dAMjQDYBMtwRAT68UNE+PKiBzHK3fA/1uT+8CbQDuYfv8+RNASwE/fFyaAJegStKqhgHAI9wBOogAgNuE8U04AlhCiAAWaWleUgPSaESz9T8BrH5WUkpio3vshJSKld14W/8AVu1SkS0Ec9gAAAAASUVORK5CYII=" }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "permutation = [ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 8] as int[]\n", "\n", "permuted = ij.op().run(\"permuteCoordinatesView\", input, permutation, 0)\n", "\n", "ij.notebook().display(permuted)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now that we have done our work on the image we want to revert the columns back to normal. Instead of using `permuteCoordinatesView` again, which would cause us to have to create another `permutation` array, we can just pass the same array to `permuteCoordinatesInverseView` to revert the image:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAApUlEQVR42u2XYQrAIAiF7eQdzaNtLBAiMleZDmbw/gTjfWW+FlyKAwCKpr7RBkDEAAgAHwDqgJxzUQD8C+AxdAMgQw5AggGNrR8BSHcDaNXdHIBMXUpQm5t3Qb1al/+BkYk7wNJBXgXQgtgCqEWHr9WRNuQgelDHcuBtKUySMAA+A9DGswtA744w6wJuTg2ACxtJ2wAppan0azV6rIBW6kmJyO3EDbx+KLUYzDJZAAAAAElFTkSuQmCC" }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "permutedBack = ij.op().run(\"permuteCoordinatesInverseView\", permuted, permutation, 0)\n", "\n", "ij.notebook().display(permutedBack)" ] } ], "metadata": { "kernelspec": { "display_name": "Groovy", "language": "groovy", "name": "groovy" }, "language_info": { "codemirror_mode": "groovy", "file_extension": ".groovy", "mimetype": "", "name": "Groovy", "nbconverter_exporter": "", "version": "2.4.3" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": false, "sideBar": false, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": false, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }