Watershed ops strange behaviour

imagej-ops
watershed

#1

@imagejan @ctrueden

I found a strange behavior using:

	opService.image().watershed(
				watershedImgLabeling,
				image,
				seedsImgLabeling,
				true,
				true,					
                                currentObjectMask );

I spend few hours tracing the strange behavior and my current hypothesis is that it crashes (see error below) when one of the seed points has a eight connectivity to a pixel outside the mask (as shown below, mask in gray, seedpoint in magenta).

When I place the pixel one further down it runs fine. Do you have any ideas?

image

java.util.NoSuchElementException
	at java.util.HashMap$HashIterator.nextNode(HashMap.java:1444)
	at java.util.HashMap$KeyIterator.next(HashMap.java:1466)
	at net.imglib2.roi.labeling.LabelingType$1.next(LabelingType.java:239)
	at net.imagej.ops.image.watershed.WatershedSeeded.compute(WatershedSeeded.java:212)
	at net.imagej.ops.image.watershed.WatershedSeeded.compute(WatershedSeeded.java:102)
	at net.imagej.ops.special.hybrid.UnaryHybridCF.run(UnaryHybridCF.java:75)
	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.image.ImageNamespace.watershed(ImageNamespace.java:596)

#2

Nice observation!

Did you try setting the useEightConnectivity input to false?

opService.image().watershed(
	watershedImgLabeling, // out?
	image,                // in
	seedsImgLabeling,     // seeds
	false,                // useEightConnectivity <--- Set this to false!
	true,	              // drawWatersheds
	currentObjectMask     // mask
);

#3

Yes, still crashes.

My workaround currently is (pseudo-code):

applyMask( seeds, erode( currentObjectMask, 2 ) );

Basically, I ensure that the seeds are at least 2 pixels away from the edge of the mask.
Using this code it never crashed.


#4

Would you mind opening an issue?


#5

done: https://github.com/imagej/imagej-ops/issues/579