I need to iterate over all the pixels in a binarized image to find shapes. But it takes a long time to iterate each image pixel in this manner. Is there any other way to iterate the image pixels in a faster manner ?
dimension = im.shape
rows = dimension[0]
cols = dimension[1]
for i in range(0,rows):
for j in range(0,cols):
doSomeOperation(im[i,j])
In general, what your
doSomeOperationdoes defines how much it can be speeded-up.If the mentioned interest in finding shapes actually means finding connected components, then a simple way to speed-up the solution is to use ndimage.label followed by ndimage.find_objects from the
scipypackage.