NumPy / SciPy: move the mask over the image and check for equality

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

+6
source share
1 answer

You can use scipy.ndimage.correlate to correlate your template with the image. Then find the bright spots that your matches will give you. 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 
+3
source

Source: https://habr.com/ru/post/889545/


All Articles