如何在每个连接的组件上迭代标签像素

问题描述 投票:0回答:1

相对于从opencv connectedComponentsWithStats检索到的源图像,迭代标签像素位置的最佳方法是什么?当前,我将标签放在源图像大小的空白背景上,如下所示,并在源图像像素上迭代以找到标签的位置:

bg = np.uint8(np.zeros(labels.shape[:2])) 
bg[np.where(labels == 1)] = 255
# Start pixel by pixel iteration on bg, but limited to their bounding box taken from stats

但是我觉得必须有一种更简单的方法,而不必将它们放在空白的背景上。有什么想法吗?

python opencv pixel connected-components
1个回答
0
投票

比我想象的要容易!您可以像这样简单地迭代标签像素。

y = np.where(labels == 1)[1]
x = np.where(labels == 1)[0]
© www.soinside.com 2019 - 2024. All rights reserved.