问题
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