Ask Your Question
0

How do is split this binary image blob, with no particular shape?

asked 2018-04-23 00:52:57 -0600

Santhosh1 gravatar image

updated 2018-04-23 01:23:28 -0600

I have a bunch of similar object on the ground being detected as blobs like the image below

image description

image description

This is how they are connected

image description

How do I separate them?

erode will make all the other objects in the image to erode as well.

Any suggestions?

edit retag flag offensive close merge delete

Comments

erode 5 times objects. Then separate object in Region of interest and dilate 5 times all roi

LBerger gravatar imageLBerger ( 2018-04-23 01:56:27 -0600 )edit

@LBerger Objective is to find the count and the approx dimension. I would be losing on the dimension if I erode only after iterate is more then 5, the objects are being split.

Santhosh1 gravatar imageSanthosh1 ( 2018-04-23 02:14:20 -0600 )edit

5 dilates and 5 erodes. you can find number 5 using connectedComponents. With a mask you can use roi and original image to find intersection points. Of course if you need a real time program this method is not good

LBerger gravatar imageLBerger ( 2018-04-23 02:38:16 -0600 )edit

I've had and solved this particular problem.

Here is a description of what I did. Unfortunately the links to the images I posted before became broken, so probably it will be harder to understand, but I do describe the solution.

http://answers.opencv.org/question/71...

Pedro Batista gravatar imagePedro Batista ( 2018-04-23 11:19:28 -0600 )edit

@LBerger I did get what you meant dilate, erode and connected components. About the time taken, I will check. I have few ideas, will try those then post the steps.

Santhosh1 gravatar imageSanthosh1 ( 2018-04-24 00:15:48 -0600 )edit

@Pedro Batista Just went through your post as well. I have a bit of a different approach to separate these two blobs, will post as soon as I'm done.

Santhosh1 gravatar imageSanthosh1 ( 2018-04-24 00:18:25 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-04-24 02:16:08 -0600

LBerger gravatar image

updated 2018-04-24 02:25:12 -0600

@Pedro Batista post incude many good idea to solve this problem too. I propose this method (and need to be tested). Shape mustn't have hole before processing : opening and closing are necessary.

    Mat imOriginal = imread("test.png", IMREAD_GRAYSCALE);
    Mat imOri = imOriginal > 1;
    Mat img = imOri.clone();
    Mat kernel;
    kernel=getStructuringElement(CV_SHAPE_CROSS, Size(3, 3));

    int nbC = 2;
    int nbIter = 0;
    Mat dst,labels;
    Mat prevErode;
    while (nbC == 2)
    {
        erode(img, dst, kernel);
        nbC = connectedComponents(dst, labels);
        nbIter++;
        if (nbC == 2)
        {
            prevErode = img.clone();
            img = dst;
        }
        imshow("erode", dst);
        waitKey(0);
    }
    Mat shape1 = labels == 1,dst1;
    Mat shape2 = labels == 2,dst2;
    Mat inter(imOri.size(), CV_8UC1, Scalar(0));
    for (int i = 0;i <= nbIter; i++)
    {
        dilate(shape1, dst1, kernel);
        dilate(shape2, dst2, kernel);
        add(inter, Scalar(1), inter, dst1&dst2);
        shape1 = dst1;
        shape2 = dst2;
    }

    imshow("Boundaries", inter>0);
    cvtColor(imOri, imOri, CV_GRAY2BGR);
    imOri.setTo(Scalar(0, 255, 0), inter > 0);
    imshow("Split shape",imOri);
    waitKey(0);
    imwrite("bilan.png",imOri);

Result is image description

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-04-23 00:52:57 -0600

Seen: 3,089 times

Last updated: Apr 24 '18