简体   繁体   English

使用 numpy/scipy 将大图像与 python 中的内核相关联

[英]Correlate a large image with a kernel in python using numpy/scipy

I have an image (10000x10000 pixels) and I have a kernel (5x5 pixels).我有一个图像(10000x10000 像素),我有一个内核(5x5 像素)。 I want to find the place(s) in the image that best matches the kernel.我想在图像中找到与内核最匹配的位置。

I vaguely remember from my studies that I need to compute a correlation coefficient for each pixel in the large image with respect to the kernel.我从我的研究中依稀记得,我需要计算大图像中每个像素相对于内核的相关系数。 But having something like (10000 - 4) * (10000 - 4) pixels to go through, I expect to get a huge performance hit doing this in python .但是有像 (10000 - 4) * (10000 - 4) 像素这样的东西,我希望在python执行此操作会获得巨大的性能。

Having only a very brief knowledge on the subject I was hoping to find something in either numpy or scipy that would do this relatively fast, but I haven't been able to find anything.对这个主题只有非常简短的了解,我希望在numpyscipy中找到一些可以相对快速地完成此操作的东西,但我什么也没找到。

Does either numpy or scipy contain a method for doing this? numpyscipy是否包含执行此操作的方法?

This is usually referred to as template matching in image processing and most image processing packages will have something for it.这通常被称为图像处理中的模板匹配,大多数图像处理包都有相应的功能。 If you can use scikit-image then you probably want match_template .如果您可以使用 scikit-image,那么您可能需要match_template Of course, OpenCV can do template matching too .当然,OpenCV 也可以做模板匹配

If you need to stick with pure scipy, it's easy enough to implement yourself: just find the maximum pixel ( argmax ) of a normalized cross-correlation ( correlate2d ).如果您需要坚持使用纯 scipy,那么实现自己很容易:只需找到归一化互相关 ( correlate2d ) 的最大像素 ( argmax )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM