用法:
skimage.feature.match_template(image, template, pad_input=False, mode='constant', constant_values=0)
使用歸一化相關性將模板與 2-D 或 3-D 圖像匹配。
輸出是一個值在 -1.0 和 1.0 之間的數組。給定位置的值對應於圖像和模板之間的相關係數。
對於 pad_input=True 匹配對應於模板的中心,否則對應於模板的左上角。要找到最佳匹配,您必須在響應(輸出)圖像中搜索峰值。
- image:(M, N[, D]) 數組
2-D 或 3-D 輸入圖像。
- template:(m, n[, d]) 數組
要定位的模板。它必須是 (m <= M, n <= N[, d <= D])。
- pad_input:bool
如果為 True,則填充圖像以使輸出與圖像大小相同,並且輸出值對應於模板中心。否則,輸出是一個形狀為 (M - m + 1, N - n + 1) 的數組,用於 (M, N) 圖像和 (m, n) 模板,並且匹配對應於原點(左上角)的模板。
- mode:見
numpy.pad
填充模式。
- constant_values:見
numpy.pad
與
mode='constant'
結合使用的常量值。
- output:數組
具有相關係數的響應圖像。
參數:
返回:
注意:
[1] 中提供了有關互相關的詳細信息。此實現使用圖像和模板的 FFT 卷積。參考文獻[2] 提供了類似的推導,但本參考文獻中提供的近似值未在我們的實現中使用。
參考:
- 1
J. P. Lewis, “Fast Normalized Cross-Correlation”, Industrial Light and Magic.
- 2
Briechle and Hanebeck, “Template Matching using Fast Normalized Cross Correlation”, Proceedings of the SPIE (2001). DOI:10.1117/12.421129
例子:
>>> template = np.zeros((3, 3)) >>> template[1, 1] = 1 >>> template array([[0., 0., 0.], [0., 1., 0.], [0., 0., 0.]]) >>> image = np.zeros((6, 6)) >>> image[1, 1] = 1 >>> image[4, 4] = -1 >>> image array([[ 0., 0., 0., 0., 0., 0.], [ 0., 1., 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.]]) >>> result = match_template(image, template) >>> np.round(result, 3) array([[ 1. , -0.125, 0. , 0. ], [-0.125, -0.125, 0. , 0. ], [ 0. , 0. , 0.125, 0.125], [ 0. , 0. , 0.125, -1. ]]) >>> result = match_template(image, template, pad_input=True) >>> np.round(result, 3) array([[-0.125, -0.125, -0.125, 0. , 0. , 0. ], [-0.125, 1. , -0.125, 0. , 0. , 0. ], [-0.125, -0.125, -0.125, 0. , 0. , 0. ], [ 0. , 0. , 0. , 0.125, 0.125, 0.125], [ 0. , 0. , 0. , 0.125, -1. , 0.125], [ 0. , 0. , 0. , 0.125, 0.125, 0.125]])
相關用法
- Python skimage.feature.graycomatrix用法及代碼示例
- Python skimage.feature.blob_doh用法及代碼示例
- Python skimage.feature.blob_dog用法及代碼示例
- Python skimage.feature.graycoprops用法及代碼示例
- Python skimage.feature.corner_orientations用法及代碼示例
- Python skimage.feature.structure_tensor用法及代碼示例
- Python skimage.feature.hessian_matrix用法及代碼示例
- Python skimage.feature.ORB用法及代碼示例
- Python skimage.feature.corner_subpix用法及代碼示例
- Python skimage.feature.canny用法及代碼示例
- Python skimage.feature.peak_local_max用法及代碼示例
- Python skimage.feature.CENSURE用法及代碼示例
- Python skimage.feature.hessian_matrix_eigvals用法及代碼示例
- Python skimage.feature.corner_foerstner用法及代碼示例
- Python skimage.feature.haar_like_feature_coord用法及代碼示例
- Python skimage.feature.corner_harris用法及代碼示例
- Python skimage.feature.corner_fast用法及代碼示例
- Python skimage.feature.BRIEF用法及代碼示例
- Python skimage.feature.haar_like_feature用法及代碼示例
- Python skimage.feature.SIFT用法及代碼示例
注:本文由純淨天空篩選整理自scikit-image.org大神的英文原創作品 skimage.feature.match_template。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。