connected components attributes in python
Question: I want to compute statistics on the connected components of a binary image. In
matlab we have

> Shape Measurements
    
    
        'Area'              'EulerNumber'       'Orientation'               
        'BoundingBox'       'Extent'            'Perimeter'          
        'Centroid'          'Extrema'           'PixelIdxList' 
        'ConvexArea'        'FilledArea'        'PixelList'
        'ConvexHull'        'FilledImage'       'Solidity' 
        'ConvexImage'       'Image'             'SubarrayIdx'            
        'Eccentricity'      'MajorAxisLength' 
        'EquivDiameter'     'MinorAxisLength' 
    

Is there any equivalent in python?

Thanks


Answer: Just answered a [similar
question](http://stackoverflow.com/questions/37147762/python-connected-
components-with-pixel-list/38706369#38706369). Use the
[`regionprops`](http://scikit-
image.org/docs/dev/api/skimage.measure.html#skimage.measure.regionprops)
function in scikit-image to get the CC properties in Python.

    
    
    from scipy.ndimage.measurements import label
    from skimage.measure import regionprops
    label = label(img)
    props = regionprops(label)
    # get centroid of second object
    centroid = props[1].centroid
    # get eccentricity of first object
    ecc = props[0].eccentricity
    

The shape measurements output by `regionprops` include all the features listed
above in the question. The `'PixelIdxList'` equivalent in Python is the
`coords` property output by `regionprops`.

