Familiar with ImageJ 1.x? Want to mix and match? Here's how.
In order to make use of ImageJ 1.x functionality, we need to ensure the ImageJ Legacy component is present on the runtime classpath.
%classpath config resolver scijava.public https://maven.scijava.org/content/groups/public
%%classpath add mvn
net.imagej imagej-legacy 0.35.0
net.imagej imagej 2.0.0-rc-71
Added new repo: scijava.public
ij = new net.imagej.ImageJ()
"ImageJ v${ij.getVersion()} is ready to go."
ImageJ v2.0.0-rc-71/1.52i is ready to go.
ImageJ2 patches ImageJ 1.x so that it can run headless. However, depending on your environment, the BeakerX kernels may not launch the JVM in headless mode by default.
Let's check whether we are running headless now:
["System property": Boolean.getBoolean("java.awt.headless"),
"UIService": ij.ui().isHeadless(),
"GraphicsEnvironment": java.awt.GraphicsEnvironment.isHeadless()]
For the most part, you can call the ImageJ1 API directly as desired:
// From: https://commons.wikimedia.org/wiki/File:Julia_set_for_f(z)%3D_z%5E14-z.png
juliaIJ1 = ij.IJ.openImage("https://upload.wikimedia.org/wikipedia/commons/thumb/e/e6/Julia_set_for_f%28z%29%3D_z%5E14-z.png/120px-Julia_set_for_f%28z%29%3D_z%5E14-z.png")
juliaIJ1.getImage()
The SciJava ConvertService
can be used to convert an ImageJ1 ImagePlus
to an ImageJ2 Dataset
:
juliaIJ2 = ij.convert().convert(juliaIJ1, net.imagej.Dataset.class)
It is also possible to convert ImageJ2 Dataset
objects to ImageJ1 ImagePlus
:
// From: https://commons.wikimedia.org/wiki/File:Mandelbrot_Grayscale_Contours.png
fractalIJ2 = ij.io().open("https://upload.wikimedia.org/wikipedia/commons/thumb/b/b8/Mandelbrot_Grayscale_Contours.png/120px-Mandelbrot_Grayscale_Contours.png")
fractalIJ1 = ij.convert().convert(fractalIJ2, ij.ImagePlus.class)
fractalIJ1.getAllStatistics()
stats[count=11520, mean=59.86666666666667, min=9.0, max=212.0]
["Count": ij.op().stats().size(fractalIJ2).getRealDouble(),
"Mean": ij.op().stats().mean(fractalIJ2).getRealDouble(),
"Min": ij.op().stats().min(fractalIJ2).getRealDouble(),
"Max": ij.op().stats().max(fractalIJ2).getRealDouble()]