{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## InterpolateView Op" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Added new repo: scijava.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": "2735a867-3146-4388-8ec0-13df7645e5db", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "net.imagej.ImageJ@7b00c550" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "//load ImageJ\n", "%classpath config resolver scijava.public https://maven.scijava.org/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.interpolate()` method of ImgLib2, [interpolating](https://en.wikipedia.org/wiki/Interpolation) any image type into a `RealRandomAccessible`. This allows a `RealRandomAccess` to be created on the `RealRandomAccessible`, allowing decimal pixels to be interrogated. Let's see how the `Op` is called:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Available operations:\n", "\t(RealRandomAccessible out) =\n", "\tnet.imagej.ops.transform.interpolateView.DefaultInterpolateView(\n", "\t\tEuclideanSpace in,\n", "\t\tInterpolatorFactory factory)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ij.op().help('interpolateView')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are two parameters to `interpolate`:\n", "* `EuclideanSpace in`: [`EuclideanSpace`](http://javadoc.scijava.org/ImgLib2/net/imglib2/EuclideanSpace.html) is a low-level interface that all image types implement. Any image can be passed in as an argument here.\n", "* `InterpolatorFactory factory`: The [`InterpolatorFactory`](http://javadoc.scijava.org/ImgLib2/index.html?net/imglib2/interpolation/InterpolatorFactory.html) tells `interpolateView()` how to create the subpixel data. As listed in the Javadoc there are many different varieties of `InterpolatorFactory`, such as [nearest neighbor](https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation), [lanzcos resampling](https://en.wikipedia.org/wiki/Lanczos_resampling), and [N-Linear](https://en.wikipedia.org/wiki/Linear_interpolation).\n", "\n", "Let's get a really small image and interpolate it:" ] }, { "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": [ "import net.imglib2.interpolation.randomaccess.NearestNeighborInterpolatorFactory\n", "import net.imglib2.interpolation.randomaccess.NLinearInterpolatorFactory\n", "import net.imglib2.interpolation.randomaccess.LanczosInterpolatorFactory\n", "\n", "scaleFactors = [4, 4, 1] // Enlarge X and Y by 4x; leave channel count the same.\n", "\n", "input = ij.scifio().datasetIO().open(\"http://imagej.net/images/ij-icon.gif\")\n", "\n", "interpolated= ij.op().run(\"interpolateView\", input, new NLinearInterpolatorFactory())\n", "\n", "ij.notebook().display(input)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that we cannot display the interpolated image since it is a `RealRandomAccessible`. However we can interrogate the image for values at decimal pixel values:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "168.0\n" ] }, { "data": { "text/plain": [ "null" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "access = interpolated.realRandomAccess()\n", "\n", "//coordinates to interrogate\n", "x = 16.6 as double\n", "y = 10.2 as double\n", "\n", "//set the randomAccess to x in the first dimension and y in the second\n", "access.setPosition(x, 0)\n", "access.setPosition(y, 1)\n", "\n", "println(access.get().getRealDouble())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you want to be able to get a `RandomAccessible` from your `RealRandomAccessible`, check out [`rasterView`](rasterView.ipynb)" ] } ], "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 }