因此,我必须使用此代码来编写与模板匹配的代码 formula。
这是我的函数的样子,如何使它起作用?返回一个介于1和0之间的值,对吧?
import numpy as np
def correlation(image_original, image_element):
altura_1, w_1, channels_1 = image_original.shape
height_2, w_2, channels_2 = image_element.shape
partial_sum_1 = float(np.sum(image_original))
average_1 = partial_sum_1 / (height_1 * w_1)
partial_sum_2 = float(np.sum(image_element))
average_2 = partial_sum_2 / (height_2 * w_2)
# Normalized Cross Correlation
top_equation = np.sum((imagem_original - average_1) * (imagem_elemento - average_2))
e1 = np.sum((image_original - average_1)**2)
e2 = np.sum((image_element - average_2)**2)
result = (top_equation) / ((e1 * e2)**(1/2))
return result