def cluster_ward(self, image_cols):
# Connectivity
# TODO optional connectivity
connectivity = grid_to_graph(*self.image.shape[:2])
ward = AgglomerativeClustering(
n_clusters=self.params.num_clusters,
linkage='ward',
connectivity=connectivity
)
ward.fit(image_cols)
self.number_of_clusters = len(np.unique(ward.labels_))
print 'number of clusters', self.number_of_clusters
centers = np.zeros((self.number_of_clusters, 3))
for i in range(0, self.number_of_clusters):
cluster_points = image_cols[ward.labels_ == i]
cluster_mean = np.mean(cluster_points, axis=0)
centers[i, :] = cluster_mean
return centers, ward.labels_
评论列表
文章目录