Skip to content

Instantly share code, notes, and snippets.

@syaffers
Created December 4, 2020 09:41
Show Gist options
  • Save syaffers/5548ad4ab5f0622a0592e39e6efa2aca to your computer and use it in GitHub Desktop.
Save syaffers/5548ad4ab5f0622a0592e39e6efa2aca to your computer and use it in GitHub Desktop.
K-means clustering on unique colors
class UniqueKMeansReducedPalette(KMeansReducedPalette):
def __init__(self, num_colors):
super().__init__(num_colors)
def fit(self, image):
image_cpy = image.copy()
pixels = self._preprocess(image_cpy)
super().fit(np.unique(pixels, axis=0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment