0

I am trying to remove noise from a binary image using contour area filtering. I have the following image:

enter image description here

And I have found the contours using the OpenCV findContours() function. The found contours are outlined in green in the following image.

enter image description here

Is there any way that I can find the area of a specific contour or do I just have to estimate the areas? E.g. Is it possible to find the area of the contour circled in red?

enter image description here

Any insights are appreciated.

3
  • Yes, it is possible, but first of all you need to segregate the contour from the other contours and then you can use cv2.findContours() to get the area
    – ZdaR
    Jul 30, 2019 at 5:41
  • What do you mean exactly by segregating the contour? And how would one be able to segregate it?
    – ceno980
    Jul 30, 2019 at 5:54
  • You need to get the bounding box of the desired contour or we can say that you need to get the location of the contour.
    – ZdaR
    Jul 30, 2019 at 6:41

1 Answer 1

1

The cv::findContours() returns an array of array of the image coordinates corresponding to each contour.

In order to find the area of each contour, you can loop through the number of detected contour and use the function cv::contourArea() on each of those array of image coordinates.

In order to find the area of the contour in the red circle, you can introduce a check inside the loop if the median points of selected contour falls inside the circle and find the area only for that contour.

What might also be useful to look into is cv::minEnclosingCircle() where you can compute the area of a minimum circle which is fit around the contour points. You can then use the center of this radius and compare it to the location in the image desired by you.

I hope this helps.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.