Conpute local weights based on the cross correlation between an image and a template