Ask Your Question
1

Filling elements

asked 2015-02-02 01:41:22 -0600

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2015-02-02 02:53:51 -0600

Michael Burdinov gravatar image

updated 2015-02-02 02:54:42 -0600

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);
edit flag offensive delete link more

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 ( 2015-02-02 20:14:25 -0600 )edit

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

Michael Burdinov gravatar imageMichael Burdinov ( 2015-02-04 00:09:35 -0600 )edit

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 ( 2015-02-04 01:48:03 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-02-02 01:41:22 -0600

Seen: 879 times

Last updated: Feb 02 '15