//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 performs a black Top-hat Transform on any binary image. Let's see how the Op
is called:
ij.op().help("blackTopHat")
Available operations: (IterableInterval out?) = net.imagej.ops.morphology.blackTopHat.ListBlackTopHat( IterableInterval out?, RandomAccessibleInterval in1, List in2)
Note the parameters here:
IterableInterval out
: the output imageRandomAccessibleInterval in1
: the input imageList in2
: this parameter contains all of the Shape
s that the Op
will use to close (i.e. for each Shape
in in2
close the input (or output of the last close
if there are 2+ Shape
s in in2
)).Let's get a grayscale image to try this out:
input_full = ij.scifio().datasetIO().open("http://imagej.net/images/blobs.gif")
//input_full has 3 channels. We only need one.
input = ij.op().run("hyperSliceView", input_full, 2, 0)
ij.notebook().display(input)
[INFO] Verifying GIF format [INFO] Reading dimensions [INFO] Reading data blocks
Now that we have our image, let's apply our Top-hat. As the Wikipedia article states,
The black top-hat returns an image, containing the "objects" or "elements" that:
- Are "smaller" than the structuring element, and
- are darker than their surroundings.
thus we did not invert the image (as we did in most of the other morphology
tutorials.
We can now apply the Top-hat. Let's use a radius of 10
for our Top-hat. This will allow us to capture most of the elements, but will also provide some
import net.imglib2.algorithm.neighborhood.HyperSphereShape
//create the shape that we are going to use in the Top-hat
shape = new HyperSphereShape(10)
output = ij.op().run("blackTopHat", null, input, [shape])
ij.notebook().display(output)
To show the difference, let's stack the images to see the difference:
import net.imglib2.img.Img
list = new ArrayList<Img>()
list.add(input)
list.add(output)
stacked = ij.op().run("stackView", list)
ij.notebook().display(stacked)
As you can see the darker objects in the (red) original image were found and the smaller the object (relative to the 10-pixel radius HyperSphereShape
), the brighter it returned.