图像将浣熊面分成5个灰度段

时间:2018-03-24 21:38:39

标签: python numpy machine-learning scipy k-means

我正在尝试将浣熊脸分成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()

0 个答案:

没有答案