Search code examples
javaimage-processingopencvjavacv

Area segmentation within a segmented area


Here's an image:

enter image description here

I would like to know how i can set the black circle to white and the rest to black.

(So segment the black circle within the white area).

I know i can invert the image and the circle will be white ... but so will the entire black part that is seen in this image.

If i would have to do this in matlab i would do a connected component operation and check the circularity of the BLOBs. Though I have to do this in opencv (javacv to be precise.)

Is there an easy way of doing this in opencv (javacv).

Thx in advance


Solution

  • There is a simple way in OpenCV using findContours() and drawContours(). If you use the hierarchical version of findContours(), you can then look through the hierarchy and draw (fill) the child contour of the white quad only. This has the additional advantage that you can do some sanity checks (e.g. checking the size of the contour to see if it is approximately the size you expect) if necessary. I don't know anything about java or javacv, but maybe you can check out the c++ example for findcontours included with opencv for inspiration?