Morpholib, not waiting for segmentation to end

Hi all,
I’m using the great morpholib for image segmentation in macro mode. Unfortunately, the ‘createResultImage’ function doesn’t wait for the segmentation to finish and for big images, outputs a copy of the original instead of the segmented one. On average, the segmentation takes 40secondes so I added a wait which works but for some images, it’s too long and a waste of time of for others, not enough stopping my macro.
Does someone have a trick to make the macro wait until the segmentation is finished without hardcoding the wait time?
even in this toy example, without wait the segmented image doen’t appear (FiJi, morpholib 1.4.1)

// load the Blobs sample image
run("Blobs (25K)");
// run the plugin
run("Morphological Segmentation");
// wait for the plugin to load
// select input image as "object"
call("inra.ijpb.plugins.MorphologicalSegmentation.setInputImageType", "object");
// set gradient radius as 1
call("inra.ijpb.plugins.MorphologicalSegmentation.setGradientRadius", "1");
// run segmentation with tolerance 32, calculating the watershed dams, 
// 4-connectivity 
call("inra.ijpb.plugins.MorphologicalSegmentation.segment", "tolerance=32",
 "calculateDams=true", "connectivity=4");
// display the overlaid dams
call("inra.ijpb.plugins.MorphologicalSegmentation.setDisplayFormat", "Watershed lines");
... postprocessing steps ....

thanks a lot,


These two posts had helped me.

Thanks @Mathew but they also use a hard coded a period of time between segmentation and segmented image generation.
I would like something like an exit status of the segmentation indicating it is finished so I can add a wait step in the macro until the exit status is detected.

Hi @Guillaume_Corre,

instead of calling the plugin, one alternative is to directly call the Watershed algorithms. There is a detailed script in the MorphoLibJ user manuel (section 1.8.1, p. 75). This would avoid calling the GUI widgets, and should avoid the use of delay.

Maybe @iarganda has better ideas, he’s more skilly than me about scripting…

thank you @dlegland,
I tried the scripting alternative but I’m not skilled enough to tune the functions and obtain the same results as with the GUI plugin.
For info, I’m trying to segment muscle fibers from cross sections, see picture below. With the ‘border’ option, it works very well.

Hello @Guillaume_Corre

This is a known problem when using macros. You might need to simply add an arbitrary waiting time.

1 Like