Search code examples
pythonopencvimage-processingimage-segmentationscikit-image

How to find each SLIC superpixel's centroid in python?


newbie here! I'm working with python plus opencv and skimage packages. I've segmented an image in superpixels using:

segments = slic(image, n_segments=numSegments, sigma=1, convert2lab=True)

Now I'd like to get the coordinates associated with each superpixel's centroid, how can I do that?


Solution

  • Try looking at skimage.measure.regionprops:

    from skimage.measure import regionprops
    
    regions = regionprops(segments)
    for props in regions:
        cx, cy = props.centroid  # centroid coordinates