用法:
cucim.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,則填充
image
以便輸出與圖像大小相同,並且輸出值對應於模板中心。否則,輸出是一個形狀為(M - m + 1, N - n + 1)
的數組,用於(M, N)
圖像和(m, n)
模板,並且匹配對應於模板的原點(左上角)。- mode:見
numpy.pad
,可選 填充模式。
- constant_values:見
numpy.pad
,可選 與
mode='constant'
結合使用的常量值。
- output:數組
具有相關係數的響應圖像。
參數:
返回:
注意:
cross-correlation 的詳細信息在 [1] 中提供。此實現使用圖像和模板的 FFT 卷積。參考文獻[2] 提供了類似的推導,但本參考文獻中提供的近似值未在我們的實現中使用。
此CuPy 實現不會在內部強製圖像為 float64,但會將 float32 用於單精度輸入。
參考:
- 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
例子:
>>> import cupy as cp >>> template = cp.zeros((3, 3)) >>> template[1, 1] = 1 >>> template array([[ 0., 0., 0.], [ 0., 1., 0.], [ 0., 0., 0.]]) >>> image = cp.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) >>> cp.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) >>> cp.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 cucim.skimage.feature.shape_index用法及代碼示例
- Python cucim.skimage.feature.corner_foerstner用法及代碼示例
- Python cucim.skimage.feature.structure_tensor_eigenvalues用法及代碼示例
- Python cucim.skimage.feature.corner_shi_tomasi用法及代碼示例
- Python cucim.skimage.feature.peak_local_max用法及代碼示例
- Python cucim.skimage.feature.structure_tensor_eigvals用法及代碼示例
- Python cucim.skimage.feature.hessian_matrix_eigvals用法及代碼示例
- Python cucim.skimage.feature.canny用法及代碼示例
- Python cucim.skimage.feature.hessian_matrix用法及代碼示例
- Python cucim.skimage.feature.corner_peaks用法及代碼示例
- Python cucim.skimage.feature.corner_kitchen_rosenfeld用法及代碼示例
- Python cucim.skimage.feature.corner_harris用法及代碼示例
- Python cucim.skimage.feature.structure_tensor用法及代碼示例
- Python cucim.skimage.filters.roberts_neg_diag用法及代碼示例
- Python cucim.skimage.filters.gabor用法及代碼示例
- Python cucim.skimage.filters.roberts_pos_diag用法及代碼示例
- Python cucim.skimage.filters.roberts用法及代碼示例
- Python cucim.skimage.filters.gabor_kernel用法及代碼示例
- Python cucim.skimage.filters.sobel_v用法及代碼示例
- Python cucim.skimage.filters.sobel_h用法及代碼示例
注:本文由純淨天空篩選整理自rapids.ai大神的英文原創作品 cucim.skimage.feature.match_template。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。