multimodalart HF staff commited on
Commit
f67edd4
·
1 Parent(s): 18b98ac

Update sketch_helper.py

Browse files
Files changed (1) hide show
  1. sketch_helper.py +4 -2
sketch_helper.py CHANGED
@@ -15,9 +15,11 @@ def color_quantization(image, n_colors):
15
  colors = kmeans.cluster_centers_
16
 
17
  # Replace each pixel with the closest color
18
- dists = np.sum((image.reshape(-1, 1, 3) - colors.reshape(1, -1, 3))**2, axis=2)
19
  labels = np.argmin(dists, axis=1)
20
- return colors[labels].reshape((image.shape[0], image.shape[1], 3)).astype(np.uint8)
 
 
21
 
22
 
23
  def get_high_freq_colors(image):
 
15
  colors = kmeans.cluster_centers_
16
 
17
  # Replace each pixel with the closest color
18
+ dists = np.sqrt(np.sum((image.reshape(-1, 1, 3) - colors.reshape(1, -1, 3))**2, axis=2))
19
  labels = np.argmin(dists, axis=1)
20
+ new_image = colors[labels].reshape(image.shape).astype(np.uint8)
21
+
22
+ return new_image)
23
 
24
 
25
  def get_high_freq_colors(image):