Spaces:
Runtime error
Runtime error
Commit
·
923fca3
1
Parent(s):
85973d3
Update sketch_helper.py
Browse files- sketch_helper.py +11 -10
sketch_helper.py
CHANGED
|
@@ -31,17 +31,18 @@ def get_high_freq_colors(image, similarity_threshold=30):
|
|
| 31 |
return [high_freq_colors, image_copy]
|
| 32 |
|
| 33 |
def color_quantization(image, color_frequency_list):
|
| 34 |
-
#
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
#
|
| 38 |
-
mask = np.
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
image[mask] = (255, 255, 255)
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
| 45 |
|
| 46 |
def create_binary_matrix(img_arr, target_color):
|
| 47 |
# Create mask of pixels with target color
|
|
|
|
| 31 |
return [high_freq_colors, image_copy]
|
| 32 |
|
| 33 |
def color_quantization(image, color_frequency_list):
|
| 34 |
+
# Convert the color frequency list to a set of unique colors
|
| 35 |
+
unique_colors = set([color for _, color in color_frequency_list])
|
| 36 |
+
|
| 37 |
+
# Create a mask for the image with True where the color is in the unique colors set
|
| 38 |
+
mask = np.any(np.all(image.reshape(-1, 1, 3) == np.array(list(unique_colors)), axis=2), axis=1).reshape(image.shape[:2])
|
| 39 |
+
|
| 40 |
+
# Create a new image with all pixels set to white
|
| 41 |
+
new_image = np.full_like(image, 255)
|
|
|
|
| 42 |
|
| 43 |
+
# Copy the pixels from the original image that have a color in the color frequency list
|
| 44 |
+
new_image[mask] = image[mask]
|
| 45 |
+
return new_image
|
| 46 |
|
| 47 |
def create_binary_matrix(img_arr, target_color):
|
| 48 |
# Create mask of pixels with target color
|