Spaces:
Runtime error
Runtime error
Colores similares al fondo chroma revisados
Browse files
app.py
CHANGED
|
@@ -19,20 +19,29 @@ import spaces
|
|
| 19 |
import numpy as np
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
# Generate random colormaps for visualizing different points.
|
| 23 |
def get_colors(num_colors: int) -> List[Tuple[int, int, int]]:
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
| 36 |
|
| 37 |
def get_points_on_a_grid(
|
| 38 |
size: int,
|
|
|
|
| 19 |
import numpy as np
|
| 20 |
|
| 21 |
|
| 22 |
+
def is_similar_to_chroma(color: Tuple[int, int, int], threshold: int = 100) -> bool:
|
| 23 |
+
"""Check if the color is similar to chroma green (RGB: 0, 255, 0)."""
|
| 24 |
+
green_chroma = np.array([0, 255, 0])
|
| 25 |
+
color_array = np.array(color)
|
| 26 |
+
distance = np.linalg.norm(color_array - green_chroma)
|
| 27 |
+
return distance < threshold
|
| 28 |
+
|
| 29 |
# Generate random colormaps for visualizing different points.
|
| 30 |
def get_colors(num_colors: int) -> List[Tuple[int, int, int]]:
|
| 31 |
+
"""Gets colormap for points, excluding colors similar to green chroma."""
|
| 32 |
+
colors = []
|
| 33 |
+
for i in np.arange(0.0, 360.0, 360.0 / num_colors):
|
| 34 |
+
hue = i / 360.0
|
| 35 |
+
lightness = (50 + np.random.rand() * 10) / 100.0
|
| 36 |
+
saturation = (90 + np.random.rand() * 10) / 100.0
|
| 37 |
+
color = colorsys.hls_to_rgb(hue, lightness, saturation)
|
| 38 |
+
color_rgb = (int(color[0] * 255), int(color[1] * 255), int(color[2] * 255))
|
| 39 |
+
|
| 40 |
+
if not is_similar_to_chroma(color_rgb):
|
| 41 |
+
colors.append(color_rgb)
|
| 42 |
+
|
| 43 |
+
random.shuffle(colors)
|
| 44 |
+
return colors[:num_colors]
|
| 45 |
|
| 46 |
def get_points_on_a_grid(
|
| 47 |
size: int,
|