RandomAccessibleInterval
s)¶//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@df84528
This notebook looks at copying RandomAccessibleInterval
s. This Op
exists for the times that copy.img()
just doesn't work:
ij.op().help("copy.rai")
Available operations: (RandomAccessibleInterval out?) = net.imagej.ops.copy.CopyRAI( RandomAccessibleInterval out?, RandomAccessibleInterval in)
import net.imglib2.FinalInterval
import net.imglib2.img.Img
import net.imglib2.IterableInterval
import net.imglib2.RandomAccessibleInterval
import net.imglib2.type.numeric.integer.UnsignedByteType
import net.imglib2.view.Views
dims = new FinalInterval(200, 150)
input1 = ij.op().create().img(dims, new UnsignedByteType())
equation1 = "127 * Math.sin(p[0] / 4) + 128"
ij.op().run("equation", input1, equation1)
input2 = ij.op().create().img(dims, new UnsignedByteType())
equation2 = "127 * Math.cos(p[1] / 4) + 128"
ij.op().run("equation", input2, equation2)
stack = Views.stack(input1, input2)
println(stack instanceof RandomAccessibleInterval)
println(stack instanceof IterableInterval)
println(stack instanceof Img)
ij.notebook().display(stack)
true false false
Copying the Img
is easy enough. All we need is the input we just made and an output image:
//Remember that output comes before input
copyRAI = ij.op().copy().rai(stack)
ij.notebook().display(copyRAI)
java.lang.ClassCastException: net.imglib2.view.StackView cannot be cast to net.imglib2.IterableInterval at net.imagej.ops.map.MapUnaryComputers$IIToIIParallel.compute(MapUnaryComputers.java:87) at net.imagej.ops.copy.CopyRAI.compute(CopyRAI.java:90) at net.imagej.ops.copy.CopyRAI.compute(CopyRAI.java:54) at net.imagej.ops.special.hybrid.UnaryHybridCF.calculate(UnaryHybridCF.java:61) at net.imagej.ops.special.hybrid.UnaryHybridCF.run(UnaryHybridCF.java:71) at net.imagej.ops.special.hybrid.UnaryHybridCF.run(UnaryHybridCF.java:97) at org.scijava.command.CommandModule.run(CommandModule.java:199) at net.imagej.ops.OpEnvironment.run(OpEnvironment.java:944) at net.imagej.ops.OpEnvironment.run(OpEnvironment.java:156) at net.imagej.ops.copy.CopyNamespace.rai(CopyNamespace.java:156) at net.imagej.ops.copy.CopyNamespace$rai.call(Unknown Source) at this cell line 2 at com.twosigma.beakerx.groovy.evaluator.GroovyCodeRunner.runScript(GroovyCodeRunner.java:94) at com.twosigma.beakerx.groovy.evaluator.GroovyCodeRunner.call(GroovyCodeRunner.java:59) at com.twosigma.beakerx.groovy.evaluator.GroovyCodeRunner.call(GroovyCodeRunner.java:32)
There also exist Op
s to copy Img
s and IterableIntervals
, which you can find by accessing these links.