Ask Your Question
1

Filling elements

asked Feb 2 '15

KansaiRobot gravatar image

Hello and thank you always.

The question

Is there any function to fill areas product say of a segmentation?

The situation

I have an image in grey. I apply threshold (or adaptive threshold) and I get a black-white image in which some areas are like big Os, (not necessary circular,also elliptical) meaning white with a black spot inside. Now some of these areas are close to each other.

What I want to get are the same areas but without the black spots inside.

What I ve tried

I ve tried to use closing. say

 kernel= getStructuringElement(MORPH_ELLIPSE, Size(7, 7));
 morphologyEx(original,closing,MORPH_CLOSE,kernel,cv::Point(-1,-1),2);

and depending on my structuring element at some point I got them closed. However since some of these areas are close to each other I also get two unrelated areas connected as a side effect. This is undesirable

Can anyone suggest to me a function to fill convex areas? or any other method to get what I want.

Thanks a thousand

Preview: (hide)

1 answer

Sort by » oldest newest most voted
4

answered Feb 2 '15

Michael Burdinov gravatar image

updated Feb 2 '15

What you actually need is to find outermost contours in black-white image and then draw them. This way you won't have holes in objects. First task can be done by findContours function. Second, by drawContours function.

vector<vector<Point> > contours;
findContours(bwImage, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
drawContours(bwImage, contours, -1, Scalar(255), CV_FILLED);
Preview: (hide)

Comments

Thank you. I will try your approach I found another way to solve it but apparently this site does not allow me to answer my own questions :(

KansaiRobot gravatar imageKansaiRobot (Feb 3 '15)edit

You are welcome. What was that another way that you found?

One using floodFill, but I tried your solution and is much more elegant, simple and it works always, while my attempt had some particular cases in which it wouldnt work. Thanks again.

KansaiRobot gravatar imageKansaiRobot (Feb 4 '15)edit

Question Tools

1 follower

Stats

Asked: Feb 2 '15

Seen: 926 times

Last updated: Feb 02 '15