使用 FFT 进行模板匹配
谁能解释一下如何使用 FFT 执行模板匹配。模板比原始图像小。 1. 到处都指出模板必须用零填充。它是如何完成的。它是添加到图像的底部和右侧,还是均匀地添加到整个图像周围。
提前致谢。
Can anyone please explain how to perform template matching using FFT. The template is smaller than the original image.
1. Everywhere it states that the template has to be padded with zeros. How it is done. Is it added to the bottom and right of the image or equally around the entire image.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在使用傅里叶变换来计算互相关;就这么简单。
围绕模板的所有面进行填充。这是因为标准快速傅立叶变换只能对 2^n 大小的数据进行操作,因此您的模板和图像的大小需要为 2^n * 2^n 。由于通常不是这样,因此通过用零填充外部来调整模板的大小以满足此要求。这些零点对 FFT 计算没有影响。
考虑使用相位相关,额外的努力很小并且可以获得很好的结果。
You are using the Fourier Transform to calculate the cross correlation; it's as simple as that.
Padding is performed around all sides of the template. This is because a standard Fast Fourier Transform can only operate on data sizes that are 2^n in size therefore your template and the image need to be 2^n * 2^n in size. Since it usually isn't, the template is resized to meet this requirement by padding the outside with zeros. These zeros have no effect on the FFT calculation.
Consider using phase correlation, the extra effort is very small and you can get great results.
Gonzalez 和 Woods 的《数字图像处理》的第 3 章和第 4 章应该可以帮助您更好地理解该理论。
您需要在图像和模板之间执行关联。在某些情况下,在频域中执行此相关操作(使用 FFT)可能会更有效,而在其他情况下,您可能希望在空间域中执行该操作。
某些软件系统使这种选择对用户透明。例如,请参阅 Mathematica 中的函数
ImageCorrelate
(http://reference .wolfram.com/mathematica/ref/ImageCorrelate.html)。The chapters 3 and 4 of Gonzalez and Woods, "Digital Image Processing" should help you acquire a better understanding of the theory.
You need to perform a correlation between your image and your template. In some cases, it may be more efficient to perform this correlation in the frequency domain (using FFT), while in others you would want to perform the operation in the spatial domain.
Some software systems make this choice transparent to the users. See for example the function
ImageCorrelate
in Mathematica (http://reference.wolfram.com/mathematica/ref/ImageCorrelate.html).这是一个很棒的资源,可以回答您的问题和一系列相关的权衡。
Here's a great resource, that answers your question and a bunch of related tradeoffs.