{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## PermuteCoordinatesView 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": "6a61caa5-ca32-46c6-8e5d-4bd044c55729", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "net.imagej.ImageJ@3baf5137" ] }, "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.permuteCoordinates()` method of ImgLib2, performing a [bijective permutation](https://en.wikipedia.org/wiki/Bijection) on the coordinates of any `RandomAccessibleInterval`. Let's see how the `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.permuteCoordinatesView.DefaultPermuteCoordinatesView(\n", "\t\tRandomAccessibleInterval in,\n", "\t\tint[] permutation)\n", "\t(IntervalView out) =\n", "\tnet.imagej.ops.transform.permuteCoordinatesView.PermuteCoordinatesViewOfDimension(\n", "\t\tRandomAccessibleInterval in,\n", "\t\tint[] permutation,\n", "\t\tint d)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ij.op().help('permuteCoordinatesView')" ] }, { "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 `permutation[i]` is any given column/row in an image, then `permutation[i]` is mapped to `i`. So if we have an `Img` of size `[5, 5]` and `permutation = [4, 3, 2, 1, 0]`, then column and row 4 are mapped to 0, column and row 3 are mapped to 1, and so on. However if `permutation = [1, 1, 1, 1, 1]` (which is in fact allowed by `permuteCoordinatesView`, then column and row 1 are mapped to 0, then column and row 1 are mapped to 1, then column and row 1 are mapped to 2, and so on, leaving all the other 4 columns and rows undefined. This is not particularly useful, but it is something to be noted. Note that the array must be larger than all of 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 all dimensions will be permuted." ] }, { "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 only permute the first dimension so that don't mix up our image too much:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAoUlEQVR42u2W3QrAIAiF7cl7tB6tMZnhLNdN6SCFQ7CLzsfMH6gsAABlGSABSikBEAA+AFQBOWdUAJwFcBu6AZChGwCZHgmAnl4paJ4eVUDmeFrvA/xvD2fBbgDpYbv+/AmgpUA+PqnV45kDPIKqaVc1dAAe4Q7AIAIAXh+MJ2EPYAmhAlikpXlpDWhHIxrdPwVYAZFSUhvdZydcsSPM7r4AclJMlI99O2wAAAAASUVORK5CYII=" }, "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, 15] as int[]\n", "\n", "permuted = ij.op().run(\"permuteCoordinatesView\", input, permutation, 0)\n", "\n", "ij.notebook().display(permuted)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we wanted to permute both dimensions of the image we could remove `d`." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAqElEQVR42u3XUQ6AIAgAUDy5R/NoNVsyMCk/AGvhxlp9xFsqJGxkAMARliPnzPKAN6DPYZvtzQCcgnZT52YUpRQzwBmwSVEB1l8BrBfdBGINgCACAOyB1cKbBngiRIDHtGAuqQBZFKLR+x8BGoiUkljobithX6aVSi8P73Z8AfYA7eYTgABMAzS2XAC+C6CnFXcAdqVVANKV/gdgPyTeAMy5Yhe05PW6AwRGTJR2j3OEAAAAAElFTkSuQmCC" }, "execution_count": 5, "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, 15] as int[]\n", "\n", "permuted = ij.op().run(\"permuteCoordinatesView\", input, permutation)\n", "\n", "ij.notebook().display(permuted)" ] } ], "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 }