-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_util.py
44 lines (36 loc) · 1.23 KB
/
_util.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
import random
import logging
def conditional_gamma_correction(channel):
if channel > 0.04045:
return ((channel + 0.055) / (1.055)) ** 2.4
else:
return channel / 12.92
def normalize_rgb(r, g, b):
return r / 255.0, g / 255.0, b / 255.0
def cie_xyz_to_xy(x_cie, y_cie, z_cie):
if (x_cie+y_cie+z_cie) == 0:
x = 0
y = 0
else:
x = x_cie / (x_cie + y_cie + z_cie)
y = y_cie / (x_cie + y_cie + z_cie)
return x, y
def cie_xyY_to_XYZ(x, y, Y):
X = (x * Y) / y
Z = (1 - x - y) * Y / y
return X, Y, Z
def generate_random_rgb():
return random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)
def setup_logger(name, level=logging.DEBUG):
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger = logging.getLogger(name)
logger.setLevel(level)
logger.addHandler(handler)
return logger
def generate_random_rgb(max_value: int=255):
# parametrising max_value to avoid simple colors (e.g. 255,0,0)
if max_value > 255:
max_value = 255
return random.randint(0, max_value), random.randint(0, max_value), random.randint(0, max_value)