watershedswatershedsWatershedsWatershedswatersheds (算子)
名称
watershedswatershedsWatershedsWatershedswatersheds — 从图像中提取分水岭和盆地。
签名
def watersheds(image: HObject) -> Tuple[HObject, HObject]
描述
watershedswatershedsWatershedsWatershedsWatershedswatersheds 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 BasinsBasinsBasinsBasinsbasinsbasins
contains these basins, while WatershedsWatershedsWatershedsWatershedswatershedswatersheds contains the
watersheds, which are at most one pixel wide.
WatershedsWatershedsWatershedsWatershedswatershedswatersheds always is a single
region per input image, while BasinsBasinsBasinsBasinsbasinsbasins contains a separate
region for each basin.
It is advisable to apply a smoothing operator (e.g.,
binomial_filterbinomial_filterBinomialFilterBinomialFilterBinomialFilterbinomial_filter or gauss_filtergauss_filterGaussFilterGaussFilterGaussFiltergauss_filter) to the input image
before calling watershedswatershedsWatershedsWatershedsWatershedswatersheds in order to reduce the number of
output regions. A more sophisticated way to reduce the number of
output regions is to merge neighboring basins based on a threshold
criterion by using watersheds_thresholdwatersheds_thresholdWatershedsThresholdWatershedsThresholdWatershedsThresholdwatersheds_threshold instead (for more
details please refer to the documentation of
watersheds_thresholdwatersheds_thresholdWatershedsThresholdWatershedsThresholdWatershedsThresholdwatersheds_threshold).
注意
If the image contains many fine structures or is noisy, many output
regions result, and thus the runtime increases considerably.
执行信息
- 多线程类型:可重入(与非独占算子并行运行)。
- 多线程作用域:全局(可从任何线程调用)。
- 在元组级别上自动并行化。
参数
ImageImageImageImageimageimage (输入对象) singlechannelimage(-array) → objectHImageHObjectHImageHobject (byte / uint2 / real)
输入图像。
BasinsBasinsBasinsBasinsbasinsbasins (输出对象) region-array → objectHRegionHObjectHRegionHobject *
Segmented basins.
WatershedsWatershedsWatershedsWatershedswatershedswatersheds (输出对象) region(-array) → objectHRegionHObjectHRegionHobject *
Watersheds between the basins.
示例 (C++ (HALCON 5.0-10.0))
#include "HIOStream.h"
#if !defined(USE_IOSTREAM_H)
using namespace std;
#endif
#include "HalconCpp.h"
using namespace Halcon;
int main (int argc, char *argv[])
{
HImage image (argv[1]), gauss;
HWindow win;
cout << "Gauss of original " << endl;
gauss = image.GaussImage (9);
image.Display (win);
HRegion watersheds;
HRegionArray basins = gauss.Watersheds (&watersheds);
win.SetColored (12);
basins.Display (win);
win.Click ();
return (0);
}
示例(C)
read_image(&Cells,"meningg5");
gauss_filter(Cells,&CellsGauss,9);
invert_image(CellsGauss,&CellsInvert);
watersheds(CellsInvert,&Bassins,&Watersheds);
set_colored(WindowHandle,12);
disp_region(Bassins,WindowHandle);
示例 (C++ (HALCON 5.0-10.0))
#include "HIOStream.h"
#if !defined(USE_IOSTREAM_H)
using namespace std;
#endif
#include "HalconCpp.h"
using namespace Halcon;
int main (int argc, char *argv[])
{
HImage image (argv[1]), gauss;
HWindow win;
cout << "Gauss of original " << endl;
gauss = image.GaussImage (9);
image.Display (win);
HRegion watersheds;
HRegionArray basins = gauss.Watersheds (&watersheds);
win.SetColored (12);
basins.Display (win);
win.Click ();
return (0);
}
示例 (C++ (HALCON 5.0-10.0))
#include "HIOStream.h"
#if !defined(USE_IOSTREAM_H)
using namespace std;
#endif
#include "HalconCpp.h"
using namespace Halcon;
int main (int argc, char *argv[])
{
HImage image (argv[1]), gauss;
HWindow win;
cout << "Gauss of original " << endl;
gauss = image.GaussImage (9);
image.Display (win);
HRegion watersheds;
HRegionArray basins = gauss.Watersheds (&watersheds);
win.SetColored (12);
basins.Display (win);
win.Click ();
return (0);
}
示例 (C++ (HALCON 5.0-10.0))
#include "HIOStream.h"
#if !defined(USE_IOSTREAM_H)
using namespace std;
#endif
#include "HalconCpp.h"
using namespace Halcon;
int main (int argc, char *argv[])
{
HImage image (argv[1]), gauss;
HWindow win;
cout << "Gauss of original " << endl;
gauss = image.GaussImage (9);
image.Display (win);
HRegion watersheds;
HRegionArray basins = gauss.Watersheds (&watersheds);
win.SetColored (12);
basins.Display (win);
win.Click ();
return (0);
}
结果
watershedswatershedsWatershedsWatershedsWatershedswatersheds 始终返回 2 ( H_MSG_TRUE )。 The behavior with
respect to the input images and output regions can be determined by
setting the values of the flags 'no_object_result'"no_object_result""no_object_result""no_object_result""no_object_result""no_object_result",
'empty_region_result'"empty_region_result""empty_region_result""empty_region_result""empty_region_result""empty_region_result", and 'store_empty_region'"store_empty_region""store_empty_region""store_empty_region""store_empty_region""store_empty_region"
with set_systemset_systemSetSystemSetSystemSetSystemset_system。如有必要,则抛出异常。
可能的前趋
binomial_filterbinomial_filterBinomialFilterBinomialFilterBinomialFilterbinomial_filter,
gauss_filtergauss_filterGaussFilterGaussFilterGaussFiltergauss_filter,
smooth_imagesmooth_imageSmoothImageSmoothImageSmoothImagesmooth_image,
invert_imageinvert_imageInvertImageInvertImageInvertImageinvert_image
可能的后继
expand_regionexpand_regionExpandRegionExpandRegionExpandRegionexpand_region,
select_shapeselect_shapeSelectShapeSelectShapeSelectShapeselect_shape,
reduce_domainreduce_domainReduceDomainReduceDomainReduceDomainreduce_domain,
openingopeningOpeningOpeningOpeningopening
替代
watersheds_thresholdwatersheds_thresholdWatershedsThresholdWatershedsThresholdWatershedsThresholdwatersheds_threshold,
pouringpouringPouringPouringPouringpouring,
watersheds_markerwatersheds_markerWatershedsMarkerWatershedsMarkerWatershedsMarkerwatersheds_marker
参考文献
L. Vincent, P. Soille: “Watersheds in Digital Space: An Efficient
Algorithm Based on Immersion Simulations”; IEEE Transactions on Pattern
Analysis and Machine Intelligence; vol. 13, no. 6; pp. 583-598; 1991.
模块
基础