-2

How I can remove this noise (rectangle 2x2px) from binary image?

enter image description here

3 Answers3

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

Median filtering (cv::medianBlur()) / morphology operations (cv::morphologyEx(), you need opening, I believe) are often used for your case - they enable cleaning out the isolated pixels. See more in here.

lysukhin
  • 127
  • 8
1

use findContours function to remove small noisy components from your image based on area.

Jazz
  • 916
  • 1
  • 8
  • 22