當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python cucim.skimage.filters.threshold_local用法及代碼示例

用法:

cucim.skimage.filters.threshold_local(image, block_size, method='gaussian', offset=0, mode='reflect', param=None, cval=0)

基於局部像素鄰域計算閾值掩碼圖像。

也稱為自適應或動態閾值。閾值是像素局部鄰域的加權平均值減去常數。或者,閾值可以由給定函數使用‘generic’ 方法動態確定。

參數

image(N, M) ndarray

輸入圖像。

block_sizeint

用於計算閾值的像素鄰域的奇數大小(例如 3、5、7、...、21、...)。

method{‘generic’, ‘gaussian’, ‘mean’, ‘median’},可選

用於確定加權平均圖像中局部鄰域的自適應閾值的方法。

  • ‘generic’:使用自定義函數(見param參數)
  • ‘gaussian’:應用高斯濾波器(請參閱param 參數以了解自定義 sigma 值)
  • ‘mean’:應用算術平均濾波器
  • ‘median’:應用中值排名過濾器

默認情況下使用‘gaussian’ 方法。

offset浮點數,可選

從鄰域的加權平均值中減去常數以計算局部閾值。默認偏移量為 0。

mode{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’},可選

mode 參數確定如何處理數組邊界,其中 cval 是 mode 等於 ‘constant’ 時的值。默認為‘reflect’。

param{int,函數},可選

為 ‘gaussian’ 方法指定 sigma 或為 ‘generic’ 方法指定函數對象。此函數將局部鄰域的平麵數組作為單個參數,並返回計算的中心像素閾值。

cval浮點數,可選

如果模式為‘constant’,則填充過去輸入邊的值。

返回

threshold(N, M) ndarray

閾值圖像。輸入圖像中高於閾值圖像中相應像素的所有像素都被視為前景。

參考

1

https://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html?highlight=threshold#adaptivethreshold

例子

>>> from skimage.data import camera
>>> image = camera()[:50, :50]
>>> binary_image1 = image > threshold_local(image, 15, 'mean')
>>> func = lambda arr: arr.mean()
>>> binary_image2 = image > threshold_local(image, 15, 'generic',
...                                         param=func)

相關用法


注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cucim.skimage.filters.threshold_local。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。