binary_thresholdbinary_thresholdBinaryThresholdBinaryThresholdbinary_threshold二值阈值(算子)
名称
binary_thresholdbinary_thresholdBinaryThresholdBinaryThresholdbinary_threshold — 使用二值阈值分割图像。
签名
void BinaryThreshold(const HObject& Image, HObject* Region, const HTuple& Method, const HTuple& LightDark, HTuple* UsedThreshold)
HRegion HImage::BinaryThreshold(const HString& Method, const HString& LightDark, HTuple* UsedThreshold) const
HRegion HImage::BinaryThreshold(const HString& Method, const HString& LightDark, Hlong* UsedThreshold) const
HRegion HImage::BinaryThreshold(const char* Method, const char* LightDark, Hlong* UsedThreshold) const
HRegion HImage::BinaryThreshold(const wchar_t* Method, const wchar_t* LightDark, Hlong* UsedThreshold) const
(
Windows only)
def binary_threshold(image: HObject, method: str, light_dark: str) -> Tuple[HObject, Sequence[Union[str, int]]]
def binary_threshold_s(image: HObject, method: str, light_dark: str) -> Tuple[HObject, Union[str, int]]
描述
binary_thresholdbinary_thresholdBinaryThresholdBinaryThresholdBinaryThresholdbinary_threshold 使用自动确定的全局阈值对单通道 ImageImageImageImageimageimage
进行分割,并将分割区域存储在 RegionRegionRegionRegionregionregion中。例如,该功能适用于在均匀照明的背景上对字符进行分割。binary_thresholdbinary_thresholdBinaryThresholdBinaryThresholdBinaryThresholdbinary_threshold 还会将使用的阈值存储在 UsedThresholdUsedThresholdUsedThresholdUsedThresholdusedThresholdused_threshold 中。
所使用的阈值由 MethodMethodMethodMethodmethodmethod 中给定的方式确定。当前该算子提供以下两种方法:'max_separability'"max_separability""max_separability""max_separability""max_separability""max_separability" 和 'smooth_histo'"smooth_histo""smooth_histo""smooth_histo""smooth_histo""smooth_histo"。这两种方法仅适用于具有双峰直方图的图像。
'smooth_histo'"smooth_histo""smooth_histo""smooth_histo""smooth_histo""smooth_histo" 方法提供了与算子 bin_thresholdbin_thresholdBinThresholdBinThresholdBinThresholdbin_threshold 相同的功能。'max_separability'"max_separability""max_separability""max_separability""max_separability""max_separability" 方法倾向于为 UsedThresholdUsedThresholdUsedThresholdUsedThresholdusedThresholdused_threshold 确定较小的值。此外,它对直方图中远离其余光谱的细小孤立峰值不敏感,且通常比 'smooth_histo'"smooth_histo""smooth_histo""smooth_histo""smooth_histo""smooth_histo" 更快。
最大化可分离性
通过选择 MethodMethodMethodMethodmethodmethod = 'max_separability'"max_separability""max_separability""max_separability""max_separability""max_separability",将调用基于 Otsu(大津法,详见参考文献中的论文)算法的灰度直方图自动阈值处理。该算法首先计算图像的直方图,然后利用统计矩找到最佳阈值 ,该阈值能将像素划分为前景与背景,并使两类像素的可分离性达到最大。此方法仅适用于 byte 和 uint2 类型的图像。
直方图平滑
通过选择 MethodMethodMethodMethodmethodmethod = 'smooth_histo'"smooth_histo""smooth_histo""smooth_histo""smooth_histo""smooth_histo",
binary_thresholdbinary_thresholdBinaryThresholdBinaryThresholdBinaryThresholdbinary_threshold 用以下方式确定阈值
:首先确定灰度值的相对直方图。随后从直方图中提取相关最小值(relevant minima),作为阈值操作的参数。为减少最小值(minima)数量,采用高斯平滑处理直方图,类似于 auto_thresholdauto_thresholdAutoThresholdAutoThresholdAutoThresholdauto_threshold。通过逐步扩大掩模尺寸,直至平滑直方图中仅存一个最小值(minima)。最终将阈值 设为此最小值(minima)的位置。
执行信息
- 多线程类型:可重入(与非独占算子并行运行)。
- 多线程作用域:全局(可从任何线程调用)。
- 在元组级别上自动并行化。
- 在内部数据级别上自动并行化。
参数
ImageImageImageImageimageimage (输入对象) singlechannelimage(-array) → objectHImageHObjectHImageHobject (byte / uint2)
输入图像。
RegionRegionRegionRegionregionregion (输出对象) region(-array) → objectHRegionHObjectHRegionHobject *
分割输出区域。
MethodMethodMethodMethodmethodmethod (输入控制) string → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
分割方法。
默认值:
'max_separability'
"max_separability"
"max_separability"
"max_separability"
"max_separability"
"max_separability"
值列表:
'max_separability'"max_separability""max_separability""max_separability""max_separability""max_separability", 'smooth_histo'"smooth_histo""smooth_histo""smooth_histo""smooth_histo""smooth_histo"
LightDarkLightDarkLightDarkLightDarklightDarklight_dark (输入控制) string → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
提取前景还是背景?
默认值:
'dark'
"dark"
"dark"
"dark"
"dark"
"dark"
值列表:
'dark'"dark""dark""dark""dark""dark", 'light'"light""light""light""light""light"
UsedThresholdUsedThresholdUsedThresholdUsedThresholdusedThresholdused_threshold (输出控制) number(-array) → HTupleSequence[Union[str, int]]HTupleHtuple (integer / string) (int / long / string) (Hlong / HString) (Hlong / char*)
使用的阈值。
可能的后继
connectionconnectionConnectionConnectionConnectionconnection,
select_shapeselect_shapeSelectShapeSelectShapeSelectShapeselect_shape,
select_grayselect_graySelectGraySelectGraySelectGrayselect_gray
替代
auto_thresholdauto_thresholdAutoThresholdAutoThresholdAutoThresholdauto_threshold,
char_thresholdchar_thresholdCharThresholdCharThresholdCharThresholdchar_threshold,
local_thresholdlocal_thresholdLocalThresholdLocalThresholdLocalThresholdlocal_threshold
另见
gray_histogray_histoGrayHistoGrayHistoGrayHistogray_histo,
thresholdthresholdThresholdThresholdThresholdthreshold
参考文献
N. Otsu, “A threshold selection method from gray level histograms",
IEEE Trans. Syst. Man. Cybern., Vol. SMC-9, 62-66 (1979).
模块
基础