本文簡要介紹 python 語言中 scipy.ndimage.grey_dilation
的用法。
用法:
scipy.ndimage.grey_dilation(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)#
使用結構元素或對應於平麵結構元素的足跡計算灰度膨脹。
灰度膨脹是一種數學形態學運算。對於完整且平坦的結構元素的簡單情況,可以將其視為滑動窗口上的最大過濾器。
- input: array_like
要計算灰度膨脹的數組。
- size: 整數元組
用於灰度膨脹的平坦且完整的結構元素的形狀。如果提供了足跡或結構,則可選。
- footprint: 整數數組,可選
用於灰度膨脹的平麵結構元素的非無限元素的位置。非零值給出了選擇最大值的中心的一組鄰居。
- structure: 整數數組,可選
用於灰度膨脹的結構元素。結構可以是非平麵結構元素。
- output: 數組,可選
可以提供用於存儲膨脹輸出的數組。
- mode: {‘reflect’,'constant','nearest','mirror',‘wrap’},可選
mode 參數確定如何處理數組邊界,其中 cval 是 mode 等於 ‘constant’ 時的值。默認為‘reflect’
- cval: 標量,可選
如果模式為‘constant’,則填充過去輸入邊的值。默認值為 0.0。
- origin: 標量,可選
origin 參數控製過濾器的位置。默認 0
- grey_dilation: ndarray
輸入的灰度膨脹。
參數 ::
返回 ::
注意:
在域 E 上定義的結構元素 s 對圖像輸入的灰度膨脹由下式給出:
(input+s)(x) = max {input(y) + s(x-y),對於 E 中的 y}
特別是,對於定義為 s(y) = 0 for y in E 的結構元素,灰度膨脹計算輸入圖像在 E 定義的滑動窗口內的最大值。
參考:
例子:
>>> from scipy import ndimage >>> import numpy as np >>> a = np.zeros((7,7), dtype=int) >>> a[2:5, 2:5] = 1 >>> a[4,4] = 2; a[2,3] = 3 >>> a array([[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 3, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) >>> ndimage.grey_dilation(a, size=(3,3)) array([[0, 0, 0, 0, 0, 0, 0], [0, 1, 3, 3, 3, 1, 0], [0, 1, 3, 3, 3, 1, 0], [0, 1, 3, 3, 3, 2, 0], [0, 1, 1, 2, 2, 2, 0], [0, 1, 1, 2, 2, 2, 0], [0, 0, 0, 0, 0, 0, 0]]) >>> ndimage.grey_dilation(a, footprint=np.ones((3,3))) array([[0, 0, 0, 0, 0, 0, 0], [0, 1, 3, 3, 3, 1, 0], [0, 1, 3, 3, 3, 1, 0], [0, 1, 3, 3, 3, 2, 0], [0, 1, 1, 2, 2, 2, 0], [0, 1, 1, 2, 2, 2, 0], [0, 0, 0, 0, 0, 0, 0]]) >>> s = ndimage.generate_binary_structure(2,1) >>> s array([[False, True, False], [ True, True, True], [False, True, False]], dtype=bool) >>> ndimage.grey_dilation(a, footprint=s) array([[0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 3, 1, 0, 0], [0, 1, 3, 3, 3, 1, 0], [0, 1, 1, 3, 2, 1, 0], [0, 1, 1, 2, 2, 2, 0], [0, 0, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) >>> ndimage.grey_dilation(a, size=(3,3), structure=np.ones((3,3))) array([[1, 1, 1, 1, 1, 1, 1], [1, 2, 4, 4, 4, 2, 1], [1, 2, 4, 4, 4, 2, 1], [1, 2, 4, 4, 4, 3, 1], [1, 2, 2, 3, 3, 3, 1], [1, 2, 2, 3, 3, 3, 1], [1, 1, 1, 1, 1, 1, 1]])
相關用法
- Python SciPy ndimage.grey_erosion用法及代碼示例
- Python SciPy ndimage.grey_closing用法及代碼示例
- Python SciPy ndimage.grey_opening用法及代碼示例
- Python SciPy ndimage.generic_laplace用法及代碼示例
- Python SciPy ndimage.generate_binary_structure用法及代碼示例
- Python SciPy ndimage.gaussian_laplace用法及代碼示例
- Python SciPy ndimage.generic_filter1d用法及代碼示例
- Python SciPy ndimage.generic_gradient_magnitude用法及代碼示例
- Python SciPy ndimage.generic_filter用法及代碼示例
- Python SciPy ndimage.gaussian_filter1d用法及代碼示例
- Python SciPy ndimage.gaussian_filter用法及代碼示例
- Python SciPy ndimage.gaussian_gradient_magnitude用法及代碼示例
- Python SciPy ndimage.geometric_transform用法及代碼示例
- Python SciPy ndimage.correlate用法及代碼示例
- Python SciPy ndimage.morphological_gradient用法及代碼示例
- Python SciPy ndimage.variance用法及代碼示例
- Python SciPy ndimage.correlate1d用法及代碼示例
- Python SciPy ndimage.binary_dilation用法及代碼示例
- Python SciPy ndimage.distance_transform_bf用法及代碼示例
- Python SciPy ndimage.find_objects用法及代碼示例
- Python SciPy ndimage.label用法及代碼示例
- Python SciPy ndimage.maximum_filter1d用法及代碼示例
- Python SciPy ndimage.iterate_structure用法及代碼示例
- Python SciPy ndimage.map_coordinates()用法及代碼示例
- Python SciPy ndimage.binary_opening用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.ndimage.grey_dilation。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。