Segment segmentation in a segmented area

Here's an image:

enter image description here

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

(So ​​segment the black circle in the white area.)

I know I can invert the image and the circle will be white ... but so will all the black part visible in this image.

If I had to do this in matlab, I would perform a connected component operation and check the roundness of the BLOB. Although I have to do it in opencv (javacv to be precise.)

Is there an easy way to do this in opencv (javacv).

thanks in advance

+3


source to share


2 answers


OpenCV has an easy way to use findContours()

and drawContours()

. If you are using the hierarchical version findContours()

, you can view the hierarchy and draw (fill) a child path of just a white square. This has the added benefit that you can do some sanity checks (for example, check the size of the outline to see if it roughly matches your size) if needed. I don't know anything about java or javacv, but maybe you can check the C ++ example for findcontours included in opencv for inspiration?



+2


source


You can detect image objects in images using openCV library (via java adapter); for this you will need to train the net for the circles.

As far as your case is concerned (perhaps this solution will not be general), you can divide the image into segments and use color change as a condition, see the pseudo-code below:

//build color switching list
List<Point> colorSwitches = ...
for(each horizontal line from image){
    for(each pixel from line){
        if(color of previous pixel != color of current pixel){
            colorSwitches.add(currentPoint)
        }
    }    
}
// so, you have detected margins of your image objects; now we need to merge neighbor pixels into image objects, where image object is collection of margin points(you should create this class)
List<ImageObject> imageObjects = ...
for(each color switch){
    if(current pixel is connected with pixels from existing image objects){
        // returns image object neared with current point
        getRelatedImageObject(imageObjects).add(currentPoint);
    }else{
        imageObjects.add(new ImageObject(currentPixel));
    }
}
// now we have list of objects from image, and we need to match objects

      



Okay, his general lines on how to do what you need, if you need more precision, I will try to explain in more detail. Also you can contact me directly

Hope this helps you.

0


source







All Articles