I 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With