如何在图像上绘制K-均值聚类

问题描述 投票:0回答:1

我正在尝试在图像上绘制K均值算法的聚类。我所能达到的只是将它们绘制在图表上。如何将它们绘制在作为背景的图像上?

此图片的大小固定,我无法更改其大小。

很抱歉这个愚蠢的问题,但是,对于python来说还很新,看起来很刺激!

我根据提供的一些示例使用了K-均值alogrithum,但直到将其绘制在图形上为止。

我想看到的是那些固定大小的自定义图像上的群集。我该如何实现。

感谢您的答复!

python-3.x image k-means
1个回答
0
投票

首先绘制图像,然后绘制点。

>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> # Image
>>> img = np.random.randint(0,255,size=(50,50))
>>> x = np.random.randint(0,50,size=100)
>>> y = np.random.randint(0,50,size=100)
>>> plt.imshow(img, cmap='gray')
>>> plt.scatter(x,y)
>>> plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.