我正在尝试将浣熊脸分成5个灰度段,我已经做到了,我仍然是新的
import numpy as np
from sklearn import cluster, datasets
from scipy import misc
import scipy as sp
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
face = sp.misc.face(gray = True)
n_clusters = 5
np.random.seed(0)
X = face.reshape((-1,1))
k_Means= cluster.KMeans(n_clusters=n_clusters,n_init=4)
k_Means.fit(X)
plt.figure(figsize=(8, 3.5))
plt.subplot(121)
plt.imshow(X, cmap='gray')
plt.axis('off')
plt.tight_layout()
plt.show()
)