5

I try to remove noises from an image. I have some black group of pixels in the image. I use cv::findContours and cv::boundingRect. And I fill small rectangles (small rectangles are noises in the image) with white colour. But this method also find me white contours (for example middle of black circle). How to find countours for black pixels? Is there any easy solution?

peter55555
  • 1,413
  • 1
  • 19
  • 36
  • findContours is a very expensive method (plus, it overwrites the original image): are you sure it wouldn't be enough a dilation + erosion (it's also called "close" operator)? http://docs.opencv.org/doc/tutorials/imgproc/erosion_dilatation/erosion_dilatation.html – Antonio Feb 18 '15 at 01:15

1 Answers1

6

Contour of black object will have an opposite orientation from a contour of white object (clockwise vs counter clockwise). You can check it by calling a function that calculates signed area:

if (contourArea(someContour,true) > 0)
    cout << "black" << endl;
else
    cout << "white" << endl;
Michael Burdinov
  • 4,348
  • 1
  • 17
  • 28
  • Thanks, but I am not the one who invented this approach. Almost every geometric library is behaving in same way, i.e. using opposite orientation for object and holes in objects, and using signed area to distinguish between them. – Michael Burdinov Feb 19 '15 at 10:56