I'm implementing the component labelling algorithm as in this paper using python and opencv. It requires checking the input image pixel-by-pixel and perform the so-called contour tracing subroutine to assign label to the blobs of a binary image.
I manage to have it running, but it seems very slow. Profiling the code shows that the for-loop to access the pixels seems to be the bottleneck. It takes about 200ms for a 256px*256px image. Here's roughly what I do:
for i in image.height:
for j in image.width:
p = image[i, j]
pa = image[i - 1, j]
pb = image[i + 1, j]
# etc...
where "image" is a binary opencv image.
I wonder if there's a faster way of doing it so that it's usable also for video applications. I'm targeting something like 40-50ms running time for the same problem size, to get 20-25fps. 10-15fps would probably be acceptable as well (66-100ms running time).
Any hints, ideas what I can do is much appreciated.