MynooMuz commited on
Commit
caa84f3
·
1 Parent(s): f964e7f

fix: strictly enforce color palette limitation by applying kmeans quantization to final extraction

Browse files
Files changed (1) hide show
  1. app.py +6 -0
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