Samuel Schmidt
Add: Distance measure
53f6094
raw
history blame
707 Bytes
import numpy as np
import cv2
def pil_cv2_image_converter(image):
numpy_image = np.array(image)
# Convert to an OpenCV image; notice the COLOR_RGB2BGR flag, which means
# that the color is converted from RGB to BGR format.
opencv_image = cv2.cvtColor(numpy_image, cv2.COLOR_RGB2BGR)
return opencv_image
def chi2_distance(histA, histB, eps = 1e-10):
# compute the chi-squared distance
d = 0.5 * np.sum([((a - b) ** 2) / (a + b + eps)
for (a, b) in zip(histA, histB)])
# return the chi-squared distance
return d
def euclidean_distance(x, y):
# compute the Euclidean distance
d = np.sqrt(np.sum((x - y) ** 2))
# return the Euclidean distance
return d