1 | initial version |
One word: connectedComponentsWithStats
For each component you can simply check if it touches the borders (left==0
or top==0
or right==cols
or bottom==rows
), and then set every pixel with the corresponding label to 0 if you want to delete it.