用法:
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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。