Python connected components with pixel list

别说谁变了你拦得住时间么 提交于 2019-12-02 04:01:56

问题


In matlab you can use

cc = bwconncomp(bimg);
pixels = cc.PixelIdxList{i}

To get pixel list of each connected components. What's the python equivalent? I tried

from skimage import measure
label = measure.label(bimg)

To get the labels, however, this does not come with pixel list.
Any suggestions?


回答1:


The regionprops function in scikit-image returns the property "coords", an (N, 2) ndarray coordinate list (row, col) of the region. I ran into the same problem and am using this to get the pixel list from the label array.




回答2:


To get pixel list of a connected component with some_label (e.g. some_label=1), if you have a labeled image:

pixels = numpy.argwhere(labeled_image == some_label)

See numpy.argwhere.

And see also this similar question.



来源:https://stackoverflow.com/questions/37147762/python-connected-components-with-pixel-list

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