本文簡要介紹 python 語言中 scipy.ndimage.sobel
的用法。
用法:
scipy.ndimage.sobel(input, axis=-1, output=None, mode='reflect', cval=0.0)#
計算 Sobel 濾波器。
- input: array_like
輸入數組。
- axis: 整數,可選
要計算的輸入軸。默認值為 -1。
- output: 數組或數據類型,可選
放置輸出的數組,或返回數組的 dtype。默認情況下,將創建一個與輸入具有相同 dtype 的數組。
- mode: str 或序列,可選
mode 參數確定當過濾器與邊框重疊時如何擴展輸入數組。通過傳遞長度等於輸入數組維數的模式序列,可以沿每個軸指定不同的模式。默認值為‘reflect’。有效值及其行為如下:
- ‘reflect’ (d c b a | a b c d | d c b a)
通過反射最後一個像素的邊來擴展輸入。此模式有時也稱為half-sample 對稱模式。
- ‘constant’ (k k k k | a b c d |呸呸呸呸)
通過使用 cval 參數定義的相同常量值填充邊之外的所有值來擴展輸入。
- ‘nearest’ (啊啊啊啊| a b c d |嘀嘀嘀嘀)
通過複製最後一個像素來擴展輸入。
- ‘mirror’ (d c b | a b c d | c b a)
通過反射最後一個像素的中心來擴展輸入。此模式有時也稱為whole-sample 對稱模式。
- ‘wrap’ (a b c d | a b c d | A B C D)
通過環繞到相對邊來擴展輸入。
為了與插值函數保持一致,還可以使用以下模式名稱:
- ‘grid-constant’
這是‘constant’ 的同義詞。
- ‘grid-mirror’
這是‘reflect’ 的同義詞。
- ‘grid-wrap’
這是‘wrap’ 的同義詞。
- cval: 標量,可選
如果模式為‘constant’,則填充過去輸入邊的值。默認值為 0.0。
- sobel: ndarray
過濾數組。具有與輸入相同的形狀。
參數 ::
返回 ::
注意:
該函數計算axis-specific Sobel 梯度。對於更高維度,可以使用水平變換(axis=0)強調水平邊,使用垂直變換(axis=1)強調垂直邊,依此類推。這些可以結合起來給出大小。
例子:
>>> from scipy import ndimage, datasets >>> import matplotlib.pyplot as plt >>> import numpy as np >>> ascent = datasets.ascent().astype('int32') >>> sobel_h = ndimage.sobel(ascent, 0) # horizontal gradient >>> sobel_v = ndimage.sobel(ascent, 1) # vertical gradient >>> magnitude = np.sqrt(sobel_h**2 + sobel_v**2) >>> magnitude *= 255.0 / np.max(magnitude) # normalization >>> fig, axs = plt.subplots(2, 2, figsize=(8, 8)) >>> plt.gray() # show the filtered result in grayscale >>> axs[0, 0].imshow(ascent) >>> axs[0, 1].imshow(sobel_h) >>> axs[1, 0].imshow(sobel_v) >>> axs[1, 1].imshow(magnitude) >>> titles = ["original", "horizontal", "vertical", "magnitude"] >>> for i, ax in enumerate(axs.ravel()): ... ax.set_title(titles[i]) ... ax.axis("off") >>> plt.show()
相關用法
- Python SciPy ndimage.spline_filter用法及代碼示例
- Python SciPy ndimage.shift用法及代碼示例
- Python SciPy ndimage.sum_labels用法及代碼示例
- Python SciPy ndimage.standard_deviation用法及代碼示例
- Python SciPy ndimage.spline_filter1d()用法及代碼示例
- Python SciPy ndimage.spline_filter1d用法及代碼示例
- 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.generic_laplace用法及代碼示例
- Python SciPy ndimage.generate_binary_structure用法及代碼示例
- Python SciPy ndimage.binary_opening用法及代碼示例
- Python SciPy ndimage.binary_fill_holes用法及代碼示例
- Python SciPy ndimage.maximum_filter用法及代碼示例
- Python SciPy ndimage.minimum_position用法及代碼示例
- Python SciPy ndimage.labeled_comprehension用法及代碼示例
- Python SciPy ndimage.grey_erosion用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.ndimage.sobel。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。