Spaces:
Running on Zero
Running on Zero
fix: strictly enforce color palette limitation by applying kmeans quantization to final extraction
Browse files
app.py
CHANGED
|
@@ -56,6 +56,12 @@ def process_image(input_image_path, color_limit, export_scale):
|
|
| 56 |
# Generate and save extraction with accurate colors
|
| 57 |
from pixelfixer.reconstruct import two_stage_pack
|
| 58 |
low = two_stage_pack(rgba, int(r["cols"]), int(r["rows"]), k_colors=k_colors)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
extract_img = Image.fromarray(low)
|
| 60 |
|
| 61 |
# Upscale using perfect multiples to maintain aspect ratio and crispness
|
|
|
|
| 56 |
# Generate and save extraction with accurate colors
|
| 57 |
from pixelfixer.reconstruct import two_stage_pack
|
| 58 |
low = two_stage_pack(rgba, int(r["cols"]), int(r["rows"]), k_colors=k_colors)
|
| 59 |
+
|
| 60 |
+
# Strictly enforce color palette if limit is set
|
| 61 |
+
if k_colors > 0:
|
| 62 |
+
from pixelfixer.quantize import kmeans_quantize
|
| 63 |
+
low, _, _ = kmeans_quantize(low, k=k_colors)
|
| 64 |
+
|
| 65 |
extract_img = Image.fromarray(low)
|
| 66 |
|
| 67 |
# Upscale using perfect multiples to maintain aspect ratio and crispness
|