Library (libraries) to use?
scikit-image或{a2}将是我的首选。在Methods? (Are there any widely used algorithms for this kind of problem?)Am I using the wrong programming language? (Is there one that offers this kind of functionality but easier to use?)
Python可以说是这个任务的“最简单”语言。在
演示
考虑一下这个图像:
仅将以下代码从6+500K减少为:import numpy as np
from skimage import io
from sklearn.cluster import KMeans
original = io.imread('https://i.stack.imgur.com/QCl8D.jpg')
n_colors = 6
arr = original.reshape((-1, 3))
kmeans = KMeans(n_clusters=n_colors, random_state=42).fit(arr)
labels = kmeans.labels_
centers = kmeans.cluster_centers_
less_colors = centers[labels].reshape(original.shape).astype('uint8')
io.imshow(less_colors)
这就是彩色量化图像的外观: