Problem with setting Connectivity for Morphological Segmentation in a macro

Tags: #<Tag:0x00007fb87e6128b0>



I’m using MorphoLibJ=>Morphological Segmentation from a macro (IJ1 macro) and encounter unstable behavior:
I try to get dams with 8-connectivity, using the following piece of code:

run("Morphological Segmentation");
selectWindow("Morphological Segmentation");
call("inra.ijpb.plugins.MorphologicalSegmentation.segment", "tolerance=50", "calculateDams=true", "connectivity=26");
call("inra.ijpb.plugins.MorphologicalSegmentation.setDisplayFormat", "Catchment basins");

but I sometimes 8-connectivity as requested and sometimes I get 4-connectivity dams.
Is there anything else I should set in Fiji to get stable results ?



That is odd. Usually for 8-connected foreground, you need 4-connected background and I would assume all dams to be 4-connected.
Why do you want 8 connected dams? You won’t be able to get the basins as 8-connected regions.
If you must have 8 connected dams, you could get the 4-connected ones invert the image and then skeletonize them.


I want to add the segmented cells to the RoiManager for further processing.
It seems that Analyze particles uses 8-connectivity, thus if I have 4-connected dams, the segmented objects cannot be separated by Analyze particles.
Is there any other workaround: eg. a way to add objects directed from MorphoLibJ to RoiManager ? a way to control the connectivity used by Analyze particles ?


I am still intrigued by the claim that it sometimes returns one or another type of connectivity.
Please post an image where this happens and one where it works as expected.


Hello @Ofra_Golani,

Can you please change the “segment” call to

call("inra.ijpb.plugins.MorphologicalSegmentation.segment", "tolerance=50", "calculateDams=true", "connectivity=8");

to make sure you use 8-connectivity? This works for me.


Thanks Ignacio

I used the recorded command. Applying the change helped. It works now !
and thanks for the great MorphoLibJ plugin !