本文簡要介紹 python 語言中 scipy.ndimage.binary_hit_or_miss
的用法。
用法:
scipy.ndimage.binary_hit_or_miss(input, structure1=None, structure2=None, output=None, origin1=0, origin2=None)#
多維二進製hit-or-miss 變換。
hit-or-miss 變換查找輸入圖像內給定圖案的位置。
- input: 數組(轉換為布爾值)
要檢測模式的二進製圖像。
- structure1: 數組(轉換為布爾值),可選
要適合輸入的前景(非零元素)的結構元素的一部分。如果未提供任何值,則選擇方形連通性 1 的結構。
- structure2: 數組(轉換為布爾值),可選
必須完全錯過前景的結構化元素的第二部分。如果沒有提供值,則取結構 1 的補碼。
- output: ndarray,可選
與輸入形狀相同的數組,其中放置輸出。默認情況下,會創建一個新數組。
- origin1: int 或整數元組,可選
結構元素結構 1 的第一部分的放置,對於居中結構,默認為 0。
- origin2: int 或整數元組,可選
結構元素結構2的第二部分的放置,對於居中結構,默認為0。如果為 origin1 而不是為 origin2 提供了值,則將 origin2 設置為 origin1。
- binary_hit_or_miss: ndarray
Hit-or-miss 輸入與給定結構元素(結構1,結構2)的變換。
參數 ::
返回 ::
參考:
例子:
>>> from scipy import ndimage >>> import numpy as np >>> a = np.zeros((7,7), dtype=int) >>> a[1, 1] = 1; a[2:4, 2:4] = 1; a[4:6, 4:6] = 1 >>> a array([[0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0]]) >>> structure1 = np.array([[1, 0, 0], [0, 1, 1], [0, 1, 1]]) >>> structure1 array([[1, 0, 0], [0, 1, 1], [0, 1, 1]]) >>> # Find the matches of structure1 in the array a >>> ndimage.binary_hit_or_miss(a, structure1=structure1).astype(int) array([[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) >>> # Change the origin of the filter >>> # origin1=1 is equivalent to origin1=(1,1) here >>> ndimage.binary_hit_or_miss(a, structure1=structure1,\ ... origin1=1).astype(int) array([[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0]])
相關用法
- Python SciPy ndimage.binary_dilation用法及代碼示例
- Python SciPy ndimage.binary_opening用法及代碼示例
- Python SciPy ndimage.binary_fill_holes用法及代碼示例
- Python SciPy ndimage.binary_closing用法及代碼示例
- Python SciPy ndimage.binary_erosion用法及代碼示例
- Python SciPy ndimage.binary_propagation用法及代碼示例
- Python SciPy ndimage.black_tophat用法及代碼示例
- Python SciPy ndimage.correlate用法及代碼示例
- Python SciPy ndimage.morphological_gradient用法及代碼示例
- Python SciPy ndimage.variance用法及代碼示例
- Python SciPy ndimage.correlate1d用法及代碼示例
- 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.maximum_filter用法及代碼示例
- Python SciPy ndimage.minimum_position用法及代碼示例
- Python SciPy ndimage.labeled_comprehension用法及代碼示例
- Python SciPy ndimage.grey_erosion用法及代碼示例
- Python SciPy ndimage.spline_filter用法及代碼示例
- Python SciPy ndimage.shift用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.ndimage.binary_hit_or_miss。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。