Consider a binarized image, I use scipy.ndimage.label()
on it and then apply the find_objects()
on the result.
Now I've got a tuple list consists of N tuples, each of them is two slice, like:
index value
0 (slice(0, 21, None) slice(0, 12, None))
1 (slice(0, 42, None) slice(7, 31, None))
. (...., ....)
which describes a x-y boundary coordinate due to the connected component.
Take index 0 tuple as an example:
slice(0, 21, None)
means the row number is from 0~21 and
slice(0, 12, None)
means the column number is from 0~12.
So we will know that this cc's area is 21 * 12 = 252
.
Now I wanna remove those connected components whose area are smaller than 300.
I already know to do this iterating over all of them. I would like to do it in a more efficient way; does anyone know how to do it?