You can calculate the minimum spanning tree and remove the longest edges. Then you can calculate the k-means. Remove another long edge and calculate the k-means. Rinse and repeat until you have N = 10. I believe this algorithm is called a simply connected k-tool, and the cluster is similar to voronoi diagrams:
"The single-channel k-clustering algorithm ... is exactly the Kruskal algorithm ... equivalent to finding MST and removing the k-1 most expensive edges."
See here: https://stats.stackexchange.com/questions/1475/visualization-software-for-clustering
Then for each cluster you apply this rule:
They highest y - 1 is the top of the rectangle. The leftmost x - 1 is the left of the rectangle. The lowest y + 1 is the bottom of the rectangle. The rightmost x + 1 is the right of the rectangle.
Note on the highest. I mean that closest to the top of the screen is not the biggest value.
source share