python
1import pyclustering 2from pyclustering.cluster import xmeans 3import numpy as np 4import pylab 5import matplotlib.pyplot as plt 6 7name=(input("元画像の名前(jpg):")+(".jpg")) 8img=plt.imread(name) 9original_shape = img.shape 10h,w,c = img.shape 11data=img.reshape(w*h, 3,1) 12data=data.reshape(len(data), -1) 13init_center = pyclustering.cluster.xmeans.kmeans_plusplus_initializer(data, 2).initialize() 14xm = pyclustering.cluster.xmeans.xmeans(data, init_center, ccore=False) 15xm.process() 16clusters = xm.get_clusters() 17pyclustering.utils.draw_clusters(data, clusters)
上記のように任意の画像を読み取りx-means法でクラスタリングして三次元グラフを出力したいのですが、クラス数がどのような画像に対しても「20」クラスとなってしまいます。
画像の読み取り方が誤っているのか、pyclusteringの使い方がおかしいのか分かりません。ご教授頂けたら幸いです。
あなたの回答
tips
プレビュー