Spaces:
Runtime error
Runtime error
Commit
·
85973d3
1
Parent(s):
7120442
Update sketch_helper.py
Browse files- sketch_helper.py +19 -1
sketch_helper.py
CHANGED
|
@@ -54,4 +54,22 @@ def create_binary_matrix(img_arr, target_color):
|
|
| 54 |
cv2.imwrite(binary_file_name, binary_matrix * 255)
|
| 55 |
|
| 56 |
#binary_matrix = torch.from_numpy(binary_matrix).unsqueeze(0).unsqueeze(0)
|
| 57 |
-
return binary_file_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
cv2.imwrite(binary_file_name, binary_matrix * 255)
|
| 55 |
|
| 56 |
#binary_matrix = torch.from_numpy(binary_matrix).unsqueeze(0).unsqueeze(0)
|
| 57 |
+
return binary_file_name
|
| 58 |
+
|
| 59 |
+
def color_distance(color1, color2):
|
| 60 |
+
return sum((a - b) ** 2 for a, b in zip(color1, color2)) ** 0.5
|
| 61 |
+
|
| 62 |
+
def replace_color(image, old_color, new_color):
|
| 63 |
+
pixels = image.load()
|
| 64 |
+
width, height = image.size
|
| 65 |
+
for x in range(width):
|
| 66 |
+
for y in range(height):
|
| 67 |
+
if pixels[x, y] == old_color:
|
| 68 |
+
pixels[x, y] = new_color
|
| 69 |
+
|
| 70 |
+
def opaque_color_on_white(color, a):
|
| 71 |
+
r, g, b = color
|
| 72 |
+
opaque_red = int((1 - a) * 255 + a * r)
|
| 73 |
+
opaque_green = int((1 - a) * 255 + a * g)
|
| 74 |
+
opaque_blue = int((1 - a) * 255 + a * b)
|
| 75 |
+
return (opaque_red, opaque_green, opaque_blue)
|