//load ImageJ
%classpath config resolver scijava.public https://maven.scijava.org/content/groups/public
%classpath add mvn net.imagej imagej 2.0.0-rc-67
//create ImageJ object
ij = new net.imagej.ImageJ()
Added new repo: scijava.public
net.imagej.ImageJ@465e45d7
This Op
wraps the Views.scale()
method of ImgLib2, enlarging the image by a set of scale factors. Let's see how the Op
is called: through the use of an interpolator and an OutOfBoundsFactory
.
ij.op().help('scaleView')
Available operations: (RandomAccessibleInterval out) = net.imagej.ops.transform.scaleView.DefaultScaleView( RandomAccessibleInterval in, double[] scaleFactors, InterpolatorFactory interpolator, OutOfBoundsFactory outOfBoundsFactory?)
Note that the Op
takes the following parameters:
RandomAccessibleInterval in
: the input imagedouble[] scaleFactors
: an array an element for each dimension that describes the factor to which that dimension is to be increased by (i.e. a value of 2 implies that the corresponding dimension should be twice as large in the output)InterpolatorFactory interpolator
: this Object tells the Op
how to interpolate the spaces in between the known data points. There are many different types of interpolation that are supported by ImageJ.OutOfBoundsFactory outOfBoundsFactory
: an optonal parameter that tells the Op
how to handle cases close to the edge of the image. Since this parameter is optional we won't worry about it here.Let's find a really small image to scale up:
input = ij.scifio().datasetIO().open("http://imagej.net/images/ij-icon.gif")
ij.notebook().display(input)
[INFO] Verifying GIF format [INFO] Reading dimensions [INFO] Reading data blocks
First, let's try scaling it using nearest neighbor interpolation:
import net.imglib2.interpolation.randomaccess.NearestNeighborInterpolatorFactory
scaleFactors = [4, 4, 1] // Enlarge X and Y by 4x; leave channel count the same.
scaled = ij.op().run("scaleView", input, scaleFactors, new NearestNeighborInterpolatorFactory())
ij.notebook().display(scaled)
Nice and pixel-y. If we want something smoother, we can try N-Linear interpolation:
import net.imglib2.interpolation.randomaccess.LanczosInterpolatorFactory
scaleFactors = [4, 4, 1] // Enlarge X and Y by 4x; leave channel count the same.
input = ij.scifio().datasetIO().open("http://imagej.net/images/ij-icon.gif")
scaled = ij.op().run("scaleView", input, scaleFactors, new LanczosInterpolatorFactory())
ij.notebook().display(scaled)
[INFO] Verifying GIF format [INFO] Reading dimensions [INFO] Reading data blocks
Be sure to take a look at interpolateView
, as it is somewhat related to our scaleView
Op
.