Spaces:
Sleeping
Sleeping
T.Masuda
commited on
Commit
·
592e0df
1
Parent(s):
21b8362
update app
Browse files- app.py +3 -3
- color.py +2 -2
- color_wheel.py +38 -38
app.py
CHANGED
|
@@ -13,11 +13,11 @@ def process_image(image, margin):
|
|
| 13 |
yield [None, None, None]
|
| 14 |
return
|
| 15 |
|
| 16 |
-
color = Color.
|
| 17 |
cwt = ColorWheel(color)
|
| 18 |
colors = []
|
| 19 |
for t in cwt.tone15:
|
| 20 |
-
cw = ColorWheel(Color.
|
| 21 |
for h in cw.hue:
|
| 22 |
colors.append((h.r, h.g, h.b))
|
| 23 |
|
|
@@ -58,8 +58,8 @@ app = gr.Interface(
|
|
| 58 |
gr.Textbox(label='text'),
|
| 59 |
],
|
| 60 |
allow_flagging='never',
|
|
|
|
| 61 |
examples=[['examples/example1.jpg', 0], ['examples/example2.jpg', 0]],
|
| 62 |
#cache_examples=False
|
| 63 |
)
|
| 64 |
-
app.queue(concurrency_count=20)
|
| 65 |
app.launch()
|
|
|
|
| 13 |
yield [None, None, None]
|
| 14 |
return
|
| 15 |
|
| 16 |
+
color = Color.from_rgb(0xff, 0x0, 0x0)
|
| 17 |
cwt = ColorWheel(color)
|
| 18 |
colors = []
|
| 19 |
for t in cwt.tone15:
|
| 20 |
+
cw = ColorWheel(Color.from_rgb(t.r, t.g, t.b))
|
| 21 |
for h in cw.hue:
|
| 22 |
colors.append((h.r, h.g, h.b))
|
| 23 |
|
|
|
|
| 58 |
gr.Textbox(label='text'),
|
| 59 |
],
|
| 60 |
allow_flagging='never',
|
| 61 |
+
concurrency_limit=20,
|
| 62 |
examples=[['examples/example1.jpg', 0], ['examples/example2.jpg', 0]],
|
| 63 |
#cache_examples=False
|
| 64 |
)
|
|
|
|
| 65 |
app.launch()
|
color.py
CHANGED
|
@@ -22,11 +22,11 @@ class Color:
|
|
| 22 |
self._b = b
|
| 23 |
|
| 24 |
@staticmethod
|
| 25 |
-
def
|
| 26 |
return Color(a, r, g, b)
|
| 27 |
|
| 28 |
@staticmethod
|
| 29 |
-
def
|
| 30 |
return Color(0xff, r, g, b)
|
| 31 |
|
| 32 |
def __eq__(self, other):
|
|
|
|
| 22 |
self._b = b
|
| 23 |
|
| 24 |
@staticmethod
|
| 25 |
+
def from_argb(a, r, g, b):
|
| 26 |
return Color(a, r, g, b)
|
| 27 |
|
| 28 |
@staticmethod
|
| 29 |
+
def from_rgb(r, g, b):
|
| 30 |
return Color(0xff, r, g, b)
|
| 31 |
|
| 32 |
def __eq__(self, other):
|
color_wheel.py
CHANGED
|
@@ -3,85 +3,85 @@ from color import Color
|
|
| 3 |
|
| 4 |
class ColorWheel:
|
| 5 |
@property
|
| 6 |
-
def
|
| 7 |
-
return self.
|
| 8 |
|
| 9 |
@property
|
| 10 |
def hue(self):
|
| 11 |
return [
|
| 12 |
-
self.
|
| 13 |
-
self.
|
| 14 |
]
|
| 15 |
|
| 16 |
@property
|
| 17 |
def tone(self):
|
| 18 |
-
return [self.
|
| 19 |
|
| 20 |
@property
|
| 21 |
def tone15(self):
|
| 22 |
-
return [self.
|
| 23 |
-
self.
|
| 24 |
-
self.
|
| 25 |
|
| 26 |
@property
|
| 27 |
-
def
|
| 28 |
-
return [self.
|
| 29 |
|
| 30 |
@property
|
| 31 |
-
def
|
| 32 |
-
return [self.
|
| 33 |
|
| 34 |
@property
|
| 35 |
-
def
|
| 36 |
-
return [self.
|
| 37 |
|
| 38 |
@property
|
| 39 |
-
def
|
| 40 |
-
return [self.
|
| 41 |
|
| 42 |
def __init__(self, c):
|
| 43 |
-
self.
|
| 44 |
self._r = c.r / 255.0
|
| 45 |
self._g = c.g / 255.0
|
| 46 |
self._b = c.b / 255.0
|
| 47 |
|
| 48 |
@staticmethod
|
| 49 |
-
def
|
| 50 |
-
r, g, b = ColorWheel.
|
| 51 |
-
c = Color.
|
| 52 |
return ColorWheel(c)
|
| 53 |
|
| 54 |
-
def
|
| 55 |
r, g, b = (self._r + value, self._g + value, self._b + value)
|
| 56 |
r = min(max(r, 0.0), 1.0)
|
| 57 |
g = min(max(g, 0.0), 1.0)
|
| 58 |
b = min(max(b, 0.0), 1.0)
|
| 59 |
-
return self.
|
| 60 |
|
| 61 |
-
def
|
| 62 |
-
h, s, v = ColorWheel.
|
| 63 |
h = (h + value) % 1.0
|
| 64 |
if h < 0.0:
|
| 65 |
h += 1.0
|
| 66 |
-
r, g, b = ColorWheel.
|
| 67 |
-
return self.
|
| 68 |
|
| 69 |
-
def
|
| 70 |
-
h, s, v = ColorWheel.
|
| 71 |
s += value
|
| 72 |
s = min(max(s, 0.0), 1.0)
|
| 73 |
-
r, g, b = ColorWheel.
|
| 74 |
-
return self.
|
| 75 |
|
| 76 |
-
def
|
| 77 |
-
h, s, v = ColorWheel.
|
| 78 |
v += value
|
| 79 |
v = min(max(v, 0.0), 1.0)
|
| 80 |
-
r, g, b = ColorWheel.
|
| 81 |
-
return self.
|
| 82 |
|
| 83 |
@staticmethod
|
| 84 |
-
def
|
| 85 |
if r < 0.0 or r > 1.0:
|
| 86 |
raise ValueError()
|
| 87 |
if g < 0.0 or g > 1.0:
|
|
@@ -108,7 +108,7 @@ class ColorWheel:
|
|
| 108 |
return h, s, v
|
| 109 |
|
| 110 |
@staticmethod
|
| 111 |
-
def
|
| 112 |
if h < 0.0 or h > 1.0:
|
| 113 |
raise ValueError()
|
| 114 |
if s < 0.0 or s > 1.0:
|
|
@@ -142,5 +142,5 @@ class ColorWheel:
|
|
| 142 |
b *= 1 - s
|
| 143 |
return r, g, b
|
| 144 |
|
| 145 |
-
def
|
| 146 |
-
return Color.
|
|
|
|
| 3 |
|
| 4 |
class ColorWheel:
|
| 5 |
@property
|
| 6 |
+
def base_color(self):
|
| 7 |
+
return self._base_color
|
| 8 |
|
| 9 |
@property
|
| 10 |
def hue(self):
|
| 11 |
return [
|
| 12 |
+
self.base_color, self.add_h(1.0 / 12), self.add_h(2.0 / 12), self.add_h(3.0 / 12), self.add_h(4.0 / 12), self.add_h(5.0 / 12),
|
| 13 |
+
self.add_h(-6.0 / 12), self.add_h(-5.0 / 12), self.add_h(-4.0 / 12), self.add_h(-3.0 / 12), self.add_h(-2.0 / 12), self.add_h(-1.0 / 12)
|
| 14 |
]
|
| 15 |
|
| 16 |
@property
|
| 17 |
def tone(self):
|
| 18 |
+
return [self.add_white(-2.0 / 16), self.add_white(-1.0 / 16), self.base_color, self.add_white(1.0 / 16), self.add_white(2.0 / 16)]
|
| 19 |
|
| 20 |
@property
|
| 21 |
def tone15(self):
|
| 22 |
+
return [self.add_white(-7.0 / 16), self.add_white(-6.0 / 16), self.add_white(-5.0 / 16), self.add_white(-4.0 / 16), self.add_white(-3.0 / 16),
|
| 23 |
+
self.add_white(-2.0 / 16), self.add_white(-1.0 / 16), self.base_color, self.add_white(1.0 / 16), self.add_white(2.0 / 16),
|
| 24 |
+
self.add_white(3.0 / 16), self.add_white(4.0 / 16), self.add_white(5.0 / 16), self.add_white(6.0 / 16), self.add_white(7.0 / 16)]
|
| 25 |
|
| 26 |
@property
|
| 27 |
+
def complementary_colors(self):
|
| 28 |
+
return [self.base_color, self.add_h(0.5)]
|
| 29 |
|
| 30 |
@property
|
| 31 |
+
def triadic_colors(self):
|
| 32 |
+
return [self.add_h(-4.0 / 12), self.base_color, self.add_h(4.0 / 12)]
|
| 33 |
|
| 34 |
@property
|
| 35 |
+
def split_complementary_colors(self):
|
| 36 |
+
return [self.add_h(-5.0 / 12), self.base_color, self.add_h(5.0 / 12)]
|
| 37 |
|
| 38 |
@property
|
| 39 |
+
def analogous_colors(self):
|
| 40 |
+
return [self.add_h(-2.0 / 12), self.add_h(-1.0 / 12), self.base_color, self.add_h(1.0 / 12), self.add_h(2.0 / 12)]
|
| 41 |
|
| 42 |
def __init__(self, c):
|
| 43 |
+
self._base_color = c
|
| 44 |
self._r = c.r / 255.0
|
| 45 |
self._g = c.g / 255.0
|
| 46 |
self._b = c.b / 255.0
|
| 47 |
|
| 48 |
@staticmethod
|
| 49 |
+
def from_hsv(h, s, v):
|
| 50 |
+
r, g, b = ColorWheel.hsv_to_rgb(h, s, v)
|
| 51 |
+
c = Color.from_rgb(round(r * 255), round(g * 255), round(b * 255))
|
| 52 |
return ColorWheel(c)
|
| 53 |
|
| 54 |
+
def add_white(self, value):
|
| 55 |
r, g, b = (self._r + value, self._g + value, self._b + value)
|
| 56 |
r = min(max(r, 0.0), 1.0)
|
| 57 |
g = min(max(g, 0.0), 1.0)
|
| 58 |
b = min(max(b, 0.0), 1.0)
|
| 59 |
+
return self._from_rgb(r, g, b)
|
| 60 |
|
| 61 |
+
def add_h(self, value):
|
| 62 |
+
h, s, v = ColorWheel.rgb_to_hsv(self._r, self._g, self._b)
|
| 63 |
h = (h + value) % 1.0
|
| 64 |
if h < 0.0:
|
| 65 |
h += 1.0
|
| 66 |
+
r, g, b = ColorWheel.hsv_to_rgb(h, s, v)
|
| 67 |
+
return self._from_rgb(r, g, b)
|
| 68 |
|
| 69 |
+
def add_s(self, value):
|
| 70 |
+
h, s, v = ColorWheel.rgb_to_hsv(self._r, self._g, self._b)
|
| 71 |
s += value
|
| 72 |
s = min(max(s, 0.0), 1.0)
|
| 73 |
+
r, g, b = ColorWheel.hsv_to_rgb(h, s, v)
|
| 74 |
+
return self._from_rgb(r, g, b)
|
| 75 |
|
| 76 |
+
def add_v(self, value):
|
| 77 |
+
h, s, v = ColorWheel.rgb_to_hsv(self._r, self._g, self._b)
|
| 78 |
v += value
|
| 79 |
v = min(max(v, 0.0), 1.0)
|
| 80 |
+
r, g, b = ColorWheel.hsv_to_rgb(h, s, v)
|
| 81 |
+
return self._from_rgb(r, g, b)
|
| 82 |
|
| 83 |
@staticmethod
|
| 84 |
+
def rgb_to_hsv(r, g, b):
|
| 85 |
if r < 0.0 or r > 1.0:
|
| 86 |
raise ValueError()
|
| 87 |
if g < 0.0 or g > 1.0:
|
|
|
|
| 108 |
return h, s, v
|
| 109 |
|
| 110 |
@staticmethod
|
| 111 |
+
def hsv_to_rgb(h, s, v):
|
| 112 |
if h < 0.0 or h > 1.0:
|
| 113 |
raise ValueError()
|
| 114 |
if s < 0.0 or s > 1.0:
|
|
|
|
| 142 |
b *= 1 - s
|
| 143 |
return r, g, b
|
| 144 |
|
| 145 |
+
def _from_rgb(self, r, g, b):
|
| 146 |
+
return Color.from_argb(self.base_color.a, round(r * 255), round(g * 255), round(b * 255))
|