Spaces:
Runtime error
Runtime error
Samuel Schmidt
commited on
Commit
·
53f6094
1
Parent(s):
9a5647a
Add: Distance measure
Browse files- src/helper.py +14 -0
src/helper.py
CHANGED
@@ -7,3 +7,17 @@ def pil_cv2_image_converter(image):
|
|
7 |
# that the color is converted from RGB to BGR format.
|
8 |
opencv_image = cv2.cvtColor(numpy_image, cv2.COLOR_RGB2BGR)
|
9 |
return opencv_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
# that the color is converted from RGB to BGR format.
|
8 |
opencv_image = cv2.cvtColor(numpy_image, cv2.COLOR_RGB2BGR)
|
9 |
return opencv_image
|
10 |
+
|
11 |
+
def chi2_distance(histA, histB, eps = 1e-10):
|
12 |
+
# compute the chi-squared distance
|
13 |
+
d = 0.5 * np.sum([((a - b) ** 2) / (a + b + eps)
|
14 |
+
for (a, b) in zip(histA, histB)])
|
15 |
+
# return the chi-squared distance
|
16 |
+
return d
|
17 |
+
|
18 |
+
def euclidean_distance(x, y):
|
19 |
+
# compute the Euclidean distance
|
20 |
+
d = np.sqrt(np.sum((x - y) ** 2))
|
21 |
+
# return the Euclidean distance
|
22 |
+
return d
|
23 |
+
|