Find connected components (4 or 8) in a binary image.