Adding pre-processing to the H-watershed code

Dear @Benoit and others,
I am working with the ImageJ’s H-watershed plugin [1] these days. I was wondering if I could add a step between the binarization and segmentation steps, such as filling binary regions.
Is this possible using the plugin? More than that, is this allowed by the H-watershed algorithm? Maybe I didn’t understand the algorithm at all :sweat_smile:
Thank you very much for your help. Kind regards,



Hi @alexdesiqueira ,

Welcome to the forum and apology or the late answer.

At the moment the plugin does not offer the option to fill holes in the labeled image. The way the algorithm works it might be possible to modify the labelling process to create a mask with filled holes. This being said I am not too inclined to complexify the plugin, and also I don’t really have time to work on it :-\

If that could still be of use to you, a workaround could be:

  1. Create a mask at the threshold, T, you have chosen. use fill holes on the mask
  2. Multiply the filled mask image by (T+1)/255
  3. Set the value of the holes to T+1: use the Max of 2 images, your original image and multiplied mask.
  4. Apply the H-watershed to result from point 3. Your holes should get filled now as they are above the threshold.

Good luck,

1 Like

Dear @Benoit,
thank you very much for your answer. I used your plugin in a paper, and when I checked your answer it was on peer review already.
But hey, it got published :smile: Please check it out at: I cited your plugin as well (The H‐watershed algorithm, in its turn, was implemented as a plugin (Lombardot, 2017) …).
Thank you for your work!
Kind regards,