NumPy/SciPy:将遮罩移到Image上并检查是否相等

Xol*_*lve 6 python numpy image-processing scipy

我正在尝试使用NumPyscipy进行图像处理.我有一个对应于背景的模板图像,我想找出它在输入图像中出现的所有位置,并将输出中相应的数组位置设置为1,否则将它们设置为0.我该怎么做?

so1*_*311 3

您可以使用 scipy.ndimage.correlate 将模板与图像相关联。然后寻找能为您提供匹配的亮点。例子:

import scipy.ndimage
from numpy import mean, std

# a, b contain image and template in numpy arrays
correlation = scipy.ndimage.correlate(a, b)
matches = (correlation-mean(correlation)) > 5*std(correlation) # tune depending on level of noise
Run Code Online (Sandbox Code Playgroud)