Matchihng algorithm based on normalised cross correlation.
        Using this matching prevents false positives occuring for bright patches in the image

def match_via_squared_difference(image, template, raw_tolerance=1, sq_diff_tolerance=0.1):
    """ Matchihng algorithm based on normalised cross correlation.
        Using this matching prevents false positives occuring for bright patches in the image
    """
    h, w = image.shape
    th, tw = template.shape
    # fft based convolution enables fast matching of large images
    correlation = fftconvolve(image, template[::-1,::-1])
    # trim the returned image, fftconvolve returns an image of width: (Temp_w-1) + Im_w + (Temp_w -1), likewise height
    correlation = correlation[th-1:h, tw-1:w]
    # find images regions which are potentially matches
    match_position_dict = get_tiles_at_potential_match_regions(image, template, correlation, raw_tolerance=raw_tolerance)
    # bright spots in images can lead to false positivies- the normalisation carried out here eliminates those
    results = calculate_squared_differences(match_position_dict, correlation, template, sq_diff_tolerance=sq_diff_tolerance)
    return results