connected components attributes in python

落花浮王杯 提交于 2019-12-08 04:54:52

问题


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


回答1:


Just answered a similar question. Use the 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.




回答2:


I think openCV's cv2 interface is what you are probably looking for.



来源:https://stackoverflow.com/questions/26791740/connected-components-attributes-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!