op().morphology().fillHoles does nothing

Umm so now that everything has been migrated to scijava pom, I have the same problem to being with which is that ij.op().morphology().fillHoles(fill, mask); does nothing.

Am using this now in the pom:


Do I have to override some inherited pom or is their other way to fill holes in the binary image using ops?

Original and Filled are just the same. Process -> Binary -> FillHoles works though.
FillHole OriginalHole


Your images are different from those in the linked old thread (I moved your post to a new topic…). Can you post an example file where you see this issue?

It’s likely that your images are treated as 3D or 4D at some point, and the “holes” aren’t holes in the depth dimension, because they touch the border. (Process > Binary > Fill Holes, on the other hand, works plane by plane always.)


Hi, Actually this solved it: Since the drawing on my images was only 1 pixel thick the holes would not be recognised without doing a dilation first:

        prebitimg = CreateBinaryImage(source, 0f ); 
	    final Shape shape = new DiamondShape(1);
		invertprebitimg = ij.op().morphology().dilate(prebitimg, shape);
		bitimg = ij.op().morphology().fillHoles((RandomAccessibleInterval<BitType>) invertprebitimg);

The fillHoles op uses a RectangleShape structuring element by default:

… which corresponds to an 8-connectivity.

Instead of dilating with a DiamondShape, you should be fine handing this DiamondShape to the fillHoles op directly to achieve 4-connectivity:

ij.op().morphology().fillHoles(output, input, new DiamondShape(1));

(Note that you have to pre-allocate an output in this call, since the optional parameters of the op signature are filled from left to right. – This drawback will hopefully be gone in the new iteration of scijava-ops.)