Identify the correct spot to place a label In the image shown below, I have a 2D data set where I have identified four clusters labeled [0,1,2,3]. I'm looking for an algorithm to place the labels in a natural* way for each shape. My first guess was to place them in the "center-of-mass" of the cluster, which is shown below. For contiguous clusters this works fine. For clusters that take a shape as in cluster 0 however, the approach fails. Without using a legend, what would be a better method to place the labels on this image?

* natural here is subjective to some extent, but the point of the labels is to help the viewer associate a certain region in the x-y plane with a number.
What about putting the label at the innermost point of the segment? Let's define innermost by the maximum of the distance transform of the segment's mask.

With software systems like Mathematica and the sort, it is straightforward to achieve.

The mask for one segment, and its distance transform:


After repeating for each segment and positioning labels where the individual distance transforms are maximum: