{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# ImgLib2 in Detail" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[ImgLib2](https://imagej.net/ImgLib2) is a general-purpose, multidimensional image processing library. Writing code using ImgLib2 is independent of image dimensionality, data type, and data storage strategy. It's designed to be reusable, to decouple algorithm development and data management, and to be extensible and adaptable through the addition of new algorithms, pixel types, and storage strategies.\n", "\n", "Find javadocs for ImgLib2 [here](https://javadoc.scijava.org/ImgLib2/)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Quick Start" ] }, { "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": "780848a5-00d5-4f5c-84d1-55ac5d486442", "version_major": 2, "version_minor": 0 }, "method": "display_data" }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "net.imagej.ImageJ@6939e9c4" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%classpath config resolver scijava.public https://maven.scijava.org/content/groups/public\n", "%classpath add mvn net.imagej imagej 2.0.0-rc-71\n", "ij = new net.imagej.ImageJ()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Creating and Displaying an Image" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The following piece of code creates and displays an 400x320 8-bit gray-level image:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import net.imglib2.img.Img\n", "import net.imglib2.img.array.ArrayImgFactory\n", "import net.imglib2.type.numeric.integer.UnsignedByteType\n", " \n", "// will create a window showing a black 400x320 image\n", "long[] dimensions = [400, 320]\n", "final Img< UnsignedByteType > img = new ArrayImgFactory<>( new UnsignedByteType() ).create( dimensions )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Breaking _lines 6-7_ into individual steps...\n", "\n", "1. `final ImgFactory< UnsignedByteType > factory = new ArrayImgFactory<>( new UnsignedByteType() );`\n", "\n", "2. `final long[] dimensions = new long[] { 400, 320 };`\n", "\n", "3. `final Img< UnsignedByteType > img = factory.create( dimensions );`\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "_Line 1:_ \n", "Pixel images in ImgLib2 are created using an [ImgFactory](https://javadoc.scijava.org/ImgLib2/net/imglib2/img/ImgFactory.html). There are different ImgFactories, that create pixel containers with different memory layouts. Here, we create an [ArrayImgFactory](https://javadoc.scijava.org/ImgLib2/net/imglib2/img/array/ArrayImgFactory.html). This factory creates containers that map to a single flat Java array.\n", "\n", "The type parameter of the factory specifies the value type of the image we want to create. We want to create a 8-bit gray-level image, thus we use [UnsignedByteType](https://javadoc.scijava.org/ImgLib2/net/imglib2/type/numeric/integer/UnsignedByteType.html).\n", "\n", "_Line 2:_\n", "Next we create a **`long[]`** array that specifies the image size in every dimension. The length of the array specifies the number of dimensions. Here, we state that we want to create 400x320 2D image.\n", "\n", "_Line 3:_\n", "We create the image, using the factory and dimensions. We store the result of the **`create()`** method in an [Img](https://javadoc.scijava.org/ImgLib2/net/imglib2/img/Img.html) variable. [Img](https://javadoc.scijava.org/ImgLib2/net/imglib2/img/Img.html) is a convenience interface that gathers properties of pixel image containers such as having a number of dimensions, being able to iterate its pixels, etc." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Opening and Displaying Image Files" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can open image files with the [IO](https://javadoc.scijava.org/SCIFIO/io/scif/img/IO.html) utility class of [SCIFIO](https://scif.io/) which calls [Bio-Formats](https://www.openmicroscopy.org/info/bio-formats) as needed. The following opens and displays an image file." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[INFO] Populating metadata\n", "[INFO] Populating metadata\n" ] }, { "data": { "text/html": [ "