Using Interactive Watershed in a Macro

(Getting import Error with the Interactive Watershed):

Hi Benoit,

I have been using the Interactive Watershed plug-in in ImageJ, and I am happy with what I obtain. However, when I try to integrated it in a macro, I am not able to get the macro to continue from there, once I manually set the parameters and click export. I would like my macro to continue working with the exported mask (result of the interactive watershed). Instead it stops. Do you have an idea on how I could do that. Thanks a lot.


1 Like

Hi Irene,

Thanks for your message. Could you share an example of the macro with which you have problems. We could do a bit of troubleshooting.

Regarding, the import error you linked: I have to admit that I am stuck with this one. The interactive watershed plugin seems to run fine but that windows pops up when it is started from the menu. I looked into it but have no clue what is trigerring the pop up. Maybe someone has ideas to suggest: @ctrueden , @imagejan or others any ideas that could get me restarted on that issue.

1 Like

Confirmed, the error pop ups under linux too.

The plugin looks very useful, some comments/suggestions:
Shouldn’t the plugin respect the hierarchy and appear under Plugins, not in the Menu bar? Hijacking the Menu bar is, I guess, not a good idea (if everybody does that, then menu would be unusable as there is not a lot of space for other entries).

The example using the blob image in the plugin page is confusing as that particular image has an inverted LUT. The page talks about “maxima” (high in the 1D plots) when you see “minima” (dark greyscale values). I understand that the plugin uses the maxima, but virtually all watersheds procedures I have seen published standardise on the minima (dark) as seeds. Sure this is a matter of image polarity, but the inverted LUT of the blobs example makes it less straightforward to grasp.

What would be also useful, although not sure if it is worth implementing is having a polarity switch, so one can process minima or maxima as desired without having to close the plugin, invert the image and run the plugin again.

Thanks for making the plugin available.

1 Like

Thanks for answering Benoit!

The macro would look like something like that:.

//Count nuclei - DAPI signal
run("Enhance Contrast...", "saturated=0.3 normalize");
run("Interactive H_Watershed");
run("Invert LUT",result3);
run("Make Binary");
run("Analyze Particles...", "size=25-Infinity display add in_situ");

So whenever I click on export after adjusting the interactive H_watershed, it does not continue with the macro…

Thanks again for the help!!


Hi Irene,

Thanks for the macro. the interactive watershed has a non blocking window. It means that when you invoke run("Interactive H_Watershed"); the script continue executing whitout waiting for user input.

One way to circumvent that is to use waitForUser macro function. After calling the interactive watershed It will pop up a window and stop the script execution until it is validated. this way it is possible to deal with the watershed tuning. I hope this helps.

Good luck with your analysis!

Hi Benoit thank you for your advice!
However, and unless there’s another way to simultaneously calling the Interactive H-watershed and the waitFor User macro function, I can’t make it work…
I have tried either before and after calling interactive H-watershed, but it stops after the later in both cases. I apologise for my insistence or ignorance… but i can’t make it work automatically. The script is always stopped after running Interactive H_watershed.

Hi Irene,

Thanks for your feedback. I misunderstood your question. What you would like to do is to run a command that executes the interactive_watershed but without user interaction. Correct me if I am wrong.

The following snippet should do the job assuming you already know which parameter to use

hMin = 20;
thresh = 100;
peakFlooding = 90;
run("H_Watershed", "impin=["+getTitle()+"] hmin="+hMin+" thresh="+thresh+" peakflooding="+peakFlooding + " outputmask=true allowsplitting=false");

H_Watershed use the same algorithm as the Interactive but without the user interaction.
I hope this will help better. If this does not answer your question give a bit more details and will find a solution soon.

Hi @Irene and @Benoit,

I moved this discussion to a new topic in the Usage & Issues category, as it was generating notifications for every new post for those following the Announcements.

1 Like

Thanks @imagejan, I did not realize that