-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpixel_utils.py
42 lines (34 loc) · 865 Bytes
/
pixel_utils.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
import colorsys
from functools import cache
@cache
def hue(pixel):
"""Return pixel hue."""
return int(colorsys.rgb_to_hls(*[i/255 for i in pixel])[0]*255)
@cache
def lightness(pixel):
"""Return pixel lightness."""
return int(colorsys.rgb_to_hls(*[i/255 for i in pixel])[1]*255)
@cache
def saturation(pixel):
"""Return pixel saturation."""
return int(colorsys.rgb_to_hls(*[i/255 for i in pixel])[2]*255)
@cache
def min_value(pixel):
"""Return minimum value of pixel."""
return min(pixel)
@cache
def max_value(pixel):
"""Return maximum value of pixel."""
return max(pixel)
@cache
def red(pixel):
"""Return red color of pixel."""
return pixel[0]
@cache
def green(pixel):
"""Return green color of pixel."""
return pixel[1]
@cache
def blue(pixel):
"""Return blue color of pixel."""
return pixel[2]