简体   繁体   中英

How can I plot K-means cluster on an image

I am trying to plot clusters from K-means alogrith on an image. All I can reach is plotting them on a graph. How can I plot them on an image as a background?

This image is of fixed size and I cant alter its size.

Sorry for silly question, but, am pretty new to python and looks exciting!

I have used K-means alogrithum based on few examples provided, but only reached upto plotting it on a graph.

What I would like to see is those clusters on a custom image of fixed size. How can I achieve it.

Thanking in advance for your replies!

First plot the image and then plot the points.

>> 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM