开发者

NumPy/SciPy: Move mask over Image and check for equality

I开发者_StackOverflow am trying to do image processing using NumPy and scipy. I have a template image corresponding to a background, and I want to find out all the places where it occurs in the input image and set the corresponding array positions in the output to 1, else set them to 0. How can I do this?


You can use scipy.ndimage.correlate to correlate your template against the image. Then look for bright spots which will give you your matches. Example:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜