Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 908
Xolve Avatar asked Jun 01 '11 14:06

Xolve


1 Answers

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
like image 198
so12311 Avatar answered Oct 10 '22 19:10

so12311