Python Imaging Library中的模板匹配(图像搜索)功能 [英] Template Matching (Image Search) function in Python Imaging Library

查看:166
本文介绍了Python Imaging Library中的模板匹配(图像搜索)功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,我需要在另一个图像(也以numpy ndarray形式)中搜索模式(以numpy ndarray形式存在)并计算模板匹配(图像中的最小差异位置).我的问题是...是否可以在Python Imaging Library或Numpy中使用任何内置图像,或者无需我手动编写函数就可以执行此操作的任何可能的图像??

I had a problem where I need to search for a pattern (present as a numpy ndarray) within another image (also present as a numpy ndarray) and compute a template match (minimum difference position in the image). My question is... is there any in-built image that I can possibly use in the Python Imaging Library or Numpy or anything possible that can do this without me manually writing a function to do so???

谢谢....

推荐答案

最好将其作为反卷积或相关性来完成. Numpy/scipy具有同时执行这两项功能的代码.

This is likely best done as an inverse convolution or correlation. Numpy/scipy has code to do both.

包括一个小例子.

转到此处获取ipython笔记本文件: http://nbviewer.ipython.org/4020770/

Go here for the ipython notebook file: http://nbviewer.ipython.org/4020770/

我做了一些高斯运算,然后将scipy.signal.correlate2d与原始图像和一小部分子集一起使用.

I made a little gaussian and then use scipy.signal.correlate2d with the original image and a small subset.

您可以看到相关性的最高值集中在拍摄图像子集的位置.请注意,对于大型内核或映像,此代码可能会花费一些时间(因为相关性很昂贵)

you can see that the highest values of the correlation are centered around where the subset of the image was taken. note that for large kernels or images, this code can take a while (because correlation is expensive)

这篇关于Python Imaging Library中的模板匹配(图像搜索)功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆