-
Notifications
You must be signed in to change notification settings - Fork 0
/
basics.py
executable file
·58 lines (36 loc) · 1.16 KB
/
basics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import numpy as np
import math
import time
import os
def assure_path_exists(path):
directory = os.path.dirname(path)
if not os.path.exists(directory):
os.makedirs(directory)
def current_milli_time():
return int(round(time.time() * 1000) % 4294967296)
def diffImage(image1, image2):
return list(zip(*np.nonzero(np.subtract(image1, image2))))
def diffPercent(image1, image2):
return len(diffImage(image1, image2)) / float(image1.size)
def numDiffs(image1, image2):
return len(diffImage(image1, image2))
def l2Distance(image1, image2):
return math.sqrt(np.sum(np.square(np.subtract(image1, image2))))
def l1Distance(image1, image2):
return np.sum(np.absolute(np.subtract(image1, image2)))
def l0Distance(image1, image2):
return np.count_nonzero(np.absolute(np.subtract(image1, image2)))
def mergeTwoDicts(x, y):
z = x.copy()
for key, value in y.items():
if key in z.keys():
z[key] += y[key]
else:
z[key] = y[key]
return z
def nprint(str):
return 0
def printDict(dictionary):
for key, value in dictionary.items():
print("%s : %s" % (key, value))
print("\n")