Counting fully connected holes in a bitmap?

I have a monochrome bitmap and I want to find the fully connected holes in the image. Only holes that are completely connected by black pixels should be included:

0000000000 0001111100 0010000010 0001000110 0000111100 0000000000 

has one hole

but

 0100000010 0100000110 0011111100 0000000000 

would have 0

+7
source share
1 answer

This is somewhat similar to CCL (Labeling of Related Components) . If you invert the bitmap, you are just looking for 4-connected drops that do not touch the edge of the image frame.

+7
source

All Articles