How I can remove this noise (rectangle 2x2px) from binary image?
Asked
Active
Viewed 551 times
-2
-
1What have you tried so far and what problems exactly are you having? – mag_zbc Sep 15 '17 at 13:09
-
Just keep the biggest black connected component – Miki Sep 15 '17 at 14:55
3 Answers
2
Both @melodisease and @Jazz suggested reasonable solutions. If you plan to go for connected components and to select those larger than a specific area, don't use findContours()
. Use a recent OpenCV and go for cv::connectedComponentsWithStats()
. You'll find it much faster.
Full disclosure: I contributed the algorithm...

Costantino Grana
- 3,132
- 1
- 15
- 35
1
use findContours
function to remove small noisy components from your image based on area.

Jazz
- 916
- 1
- 8
- 22