//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() ij.op().help("blackTopHat") 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) 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) import net.imglib2.img.Img list = new ArrayList() list.add(input) list.add(output) stacked = ij.op().run("stackView", list) ij.notebook().display(stacked)