Watershed Algorithm

This function block performs region-based segmentation using supplied foreground and background masks to separate touching or overlapping objects. It returns a visual overlay with boundaries and a labeled segmentation map for downstream processing.

πŸ“₯ Inputs

Image Any The original color or grayscale image to segment.

Fore Ground A binary/grayscale image indicating sure-foreground regions (objects).

Back Ground A binary/grayscale image indicating sure-background regions.

πŸ“€ Outputs

Image Any The original image with detected region boundaries overlaid (visual result).

Shed Image A labeled image (grayscale) representing segmented regions / markers.

πŸ•ΉοΈ Controls

This function block has no adjustable widgets. Provide accurate Fore Ground and Back Ground inputs to control the segmentation result.

βš™οΈ Running mechanism

  • The block uses the provided Fore Ground and Back Ground masks to determine which pixels are definitely object and which are definitely background.

  • It identifies the unknown region between these masks and assigns intermediate markers.

  • A segmentation pass separates regions, draws the detected boundaries on a copy of the input image, and produces a labeled Shed Image where each segmented region has a distinct marker value.

  • The overlaid image highlights boundaries for quick visual inspection while the labeled image is suitable for measurements or counting.

🎯 Features

  • Works well for separating touching objects when clear foreground/background masks are provided.

  • Produces both a visual overlay for inspection and a labeled output useful for further processing (measurements, counting, extraction).

  • Accepts color or grayscale input images.

πŸ“ Usage instructions

  1. Prepare a clear Fore Ground mask covering the interior of objects and a complementary Back Ground mask for the background.

  2. Connect the original image to Image Any and the two masks to their respective inputs.

  3. Run the block to obtain the segmented overlay and the labeled Shed Image.

  4. Use the labeled image for downstream tasks such as object counting or extracting individual regions.

πŸ’‘ Tips and Tricks

  • Use Image Threshold, Image Adaptive Threshold, or HSV Filter to create initial binary masks from the input image.

  • Clean up small holes and noise in masks with Morphological Transformations or Denoising before feeding them into this block.

  • For difficult backgrounds, try Grab Cut Algorithm or Background Subtractor to generate better foreground/background candidates.

  • Restrict processing to a region of interest with Image ROI or Image ROI Select to speed up segmentation and avoid irrelevant areas.

  • Preview masks and results with Show Image and save useful frames using Image Logger or Image Write.

  • After segmentation, use Find Contour, Minimum Rectangle, or Measure Object Distance to extract region properties and measurements from the labeled Shed Image.

πŸ› οΈ Troubleshooting

  • Poor segmentation or merged objects: check that Fore Ground covers only object interiors and Back Ground covers only background; add morphological opening/closing to refine masks.

  • No boundaries visible: verify that the input images and masks are valid image types (not empty) and that masks are binary or clearly contrasted.

  • Over-segmentation (too many small regions): smooth or simplify masks using Blur, Denoising, or Morphological Transformations before segmentation.

  • Under-segmentation (objects not separated): increase the accuracy of foreground markers (use stronger object markers or manual ROI selection) to help separate touching objects.

Last updated

Was this helpful?