Adding Text Labels to Cells in an Image

### Adding text labels to cells in an image

# One way (of many) for getting the coordinates of labeled cells
from scipy.ndimage.measurements import center_of_mass 

# Prepare the image
plt.figure(figsize=(10,10))
plt.imshow(array_of_labeled_objects, interpolation='none', cmap='inferno')

# Iterate over cell labels...
for label in np.unique(array_of_labeled_objects)[1:]:
    
    # Get coordinates of the cell
    coords = center_of_mass(array_of_labeled_objects == label )
    
    # Add the cell ID to the image
    plt.text(int(coords[1])-15, int(coords[0])+5, label , color='w')
    
# Done
plt.show()
Edited by Jonas Hartmann