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


Python skimage.restoration.rolling_ball用法及代碼示例

用法:

skimage.restoration.rolling_ball(image, *, radius=100, kernel=None, nansafe=False, num_threads=None)

通過滾動/平移內核來估計背景強度。

在曝光不均勻的情況下,這種滾球算法會估計 ndimage 的背景強度。它是常用的滾球算法[1]的推廣。

參數

imagendarray

要過濾的圖像。

radiusint 可選

要在圖像中滾動/平移的球形內核的半徑。如果 kernel = None 使用。

kernelndarray,可選

要在圖像中滾動/翻譯的內核。它必須具有與 image 相同的維數。內核在該位置填充了內核的強度。

nansafe: bool, optional

如果 False (默認)假定 image 中的所有值都不是 np.nan ,並使用更快的實現。

num_threads: int, optional

要使用的最大線程數。如果None使用OpenMP默認值;通常等於最大虛擬內核數。注意:這是線程數的上限。確切的數字由係統的OpenMP 庫確定。

返回

backgroundndarray

圖像的估計背景。

注意

對於估計了其背景強度的像素(在 center 處不失一般性),滾動球方法將 kernel 居中並提升內核直到表麵在某個 pos=(y,x) 處接觸圖像本影。然後使用該位置的圖像強度 (image[pos]) 加上 kernel[center] - kernel[pos] 的差異來估計背景強度。

該算法假設暗像素對應於背景。如果您有明亮的背景,請在將圖像傳遞給函數之前反轉圖像,例如,使用 utils.invert 有關詳細信息,請參閱圖庫示例。

該算法對噪聲(尤其是椒鹽噪聲)敏感。如果這是您的圖像中的問題,您可以在將圖像傳遞給此函數之前應用溫和的高斯平滑。

參考

1

Sternberg, Stanley R. “Biomedical image processing.” Computer 1 (1983): 22-34. DOI:10.1109/MC.1983.1654163

例子

>>> import numpy as np
>>> from skimage import data
>>> from skimage.restoration import rolling_ball
>>> image = data.coins()
>>> background = rolling_ball(data.coins())
>>> filtered_image = image - background
>>> import numpy as np
>>> from skimage import data
>>> from skimage.restoration import rolling_ball, ellipsoid_kernel
>>> image = data.coins()
>>> kernel = ellipsoid_kernel((101, 101), 75)
>>> background = rolling_ball(data.coins(), kernel=kernel)
>>> filtered_image = image - background

相關用法


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