What's the best way to iterate over labels pixel positions in relation to source image retrieved from opencv connectedComponentsWithStats
? Currently, I'm putting the labels over a blank background the size of the source image like the following and iterative over the source image pixels to find where the labels are located:
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
but I feel like there must be an easier way doing it without having to put them on a blank background. Any thoughts?