Extract watersheds and basins from an image.
watersheds segments an image based on the topology of the gray values: The image is interpreted as a ``mountain range.'' Higher gray values correspond to ``mountains,'' while lower gray values correspond to ``valleys.'' In the resulting mountain range watersheds are extracted. These correspond to the bright ridges between dark basins. On output, the parameter Basins contains these basins, while Watersheds contains the watersheds, which are at least one pixel wide (points on the ridge which form a plateau). Watersheds always is a single region per input image, while Basins contains a separate region for each basin. It is advisable to apply a smoothing operator (e.g., gauss__) to the input image before calling watersheds in order to reduce the number of output regions.
If the image contains many fine structures or is noisy, many output regions result, and thus the runtime increases considerably.
GreyImage (input_object) |
image(-array) -> object : byte |
Images to be segmented. |
Basins (output_object) |
region-array -> object |
Segments found (dark basins). |
Watersheds (output_object) |
region(-array) -> object |
Watersheds between the basins. |
#include#include "HCPP.H" int main (int argc, char *argv[]) { HImage image (argv[1]), invert, gauss; HWindow win; cout << "Gauss of original " << endl; gauss = image.Gauss (9); image.Display (win); cout << "Invert of Gauss " << endl; invert = gauss.Invert (); invert.Display (win); HRegion watersheds; HRegionArray bassins = invert.Watersheds (&watersheds); win.SetColored (12); bassins.Display (win); win.Click (); return (0); }
watersheds always returns TRUE. The behaviour with respect to the input images and output regions can be determined by setting the values of the flags 'no_object_result', 'empty_region_result', and 'store_empty_region' with set_system. If necessary, an exception is raised.
expand, select_shape, reduce_domain, opening