//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@3baf5137
This Op
wraps the Views.extendValue()
method of ImgLib2, removing the borders of any RandomAccessibleInterval
(which transforms it into a RandomAccessible
) and filling in all the new pixels with a given value. Let's see how it is called:
ij.op().help('extendValueView')
Available operations: (ExtendedRandomAccessibleInterval out) = net.imagej.ops.transform.extendValueView.DefaultExtendValueView( RandomAccessibleInterval in, Type value)
Since this Op
can't really vary using parameters because of its strict definition, we only have to pass through an input and a value.
input = ij.scifio().datasetIO().open("http://imagej.net/images/clown.png")
ij.notebook().display(input)
Let's find a more interesting section instead of running the Op
on the whole image:
import net.imglib2.FinalInterval
region = FinalInterval.createMinSize(30, 17, 0, 85, 78, 3)
eye = ij.op().run("crop", input, region)
ij.notebook().display(eye)
Now that we have a smaller section, let's extend the border Note that the value has to be of the same Type
as the image pixel values. We will also use pad
so that we can see the new pixels:
import net.imglib2.type.numeric.integer.UnsignedByteType
def pad(image, extended, t, r, b, l) {
min = new long[image.numDimensions()]
max = new long[image.numDimensions()]
image.min(min)
image.max(max)
min[0] -= l; min[1] -= t; max[0] += r; max[1] += b
return ij.op().run("intervalView", extended, min, max)
}
value = new UnsignedByteType(90)
extended = ij.op().run("extendValueView", eye, value)
//let's extend our image out 20 pixels on each side
padLength = 40
padded = pad(eye, extended, padLength, padLength, padLength, padLength)
ij.notebook().display(padded)