# Convex Hull for Added Contours

Hi Guys.

Is it possible to detect a drawn convex hull that resides in another? If a convex hull is drawn inside a smaller one, I want to ignore it and only keep the bigger one.

Is there a way to do this?

edit retag close merge delete

Can you explain it with a picture?

( 2014-09-18 09:17:59 -0500 )edit

Sure! :) Here's the image: Image I know my lines are a bit thick but if you look closely you can see two rectangles. I wish to only keep the larger of the two rectangles each time this happens.

Is it possible?

Thank you!

( 2014-09-18 09:31:13 -0500 )edit

Sort by ยป oldest newest most voted

Hi!

You can try this approach!

1. Apply Binary thresholding to the image.

1. Find contours with CV_RETR_LIST
2. Now filter the contours based on contour Area.
3. You can find the required two smaller contours marked as red.
4. Now create new contour set named as vector<point> merged_contour_points;
5. Add these smaller contours in merged_contour_points.

e.g merged_contour_points.push_back(contours[i]);// filtered smaller contours.

6. Find Convex hull for the Merged contour points. Hope this helps for your problem.
more

This won't work if I have multiple sets of this in one image right? For my interest areas, some have hulls in hulls some are nicely bounded by hulls.

( 2014-09-19 08:16:34 -0500 )edit

you need to specify what is your actual case, this will work only for this particular problem.

( 2014-09-19 08:28:18 -0500 )edit

Lets say I have 4 areas of interest. After hulling, 2 of the areas appear as in the image attached (hull in hull) and the other two only have one bounding hull each.

I'm looking to somehow find a way to delete the smaller hull in the first two. Is it possible to get the coordinates of the hulls? Perhaps I can extract the coordinates of each hull and somehow see if one lies in another?

( 2014-09-19 08:45:56 -0500 )edit

it would be very useful if you describe your problem using image. Can you draw share the picture with necessary details?

( 2014-09-19 09:01:44 -0500 )edit

See this Image

Lets say the red boxes are my points of interest. Since I was unable to get a clean contour, I have in some cases 2 hulls (black lines) on one point while some have only one.

I wish to only have one hull for each point of interest. So where there are 2 hulls on one point of interest, I wish to only keep one. Either the bigger or the smaller of the two.

( 2014-09-19 20:33:40 -0500 )edit

I found a way to solve the problem. Thanks for all your help though! Really appreciate it!

( 2014-09-21 07:40:31 -0500 )edit

Yes, just see the parameters of findContours. To be more explicit, use :

cv::findContours(imageIn, contoursOut, hierarchyOut, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);


You can also see this for some info about the hierarchy, if you need it.

more

I tried using hierarchy but not all my points of interest have been identified to be on the same level. I'm assuming you mean only draw hull if (hierarchy[i][3] != -1) or similar right?

Is there another way to do this? I tried to hull my hull vector hoping it would just consume the smaller one and just output one that envelopes the two.

( 2014-09-18 21:37:34 -0500 )edit