Ask Your Question
0

Convex Hull for Added Contours

asked 2014-09-18 08:32:13 -0600

Icetray gravatar image

updated 2014-09-19 06:02:29 -0600

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 flag offensive close merge delete

Comments

Can you explain it with a picture?

Balaji R gravatar imageBalaji R ( 2014-09-18 09:17:59 -0600 )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!

Icetray gravatar imageIcetray ( 2014-09-18 09:31:13 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2014-09-19 01:13:12 -0600

Hi!

You can try this approach!

  1. Apply Binary thresholding to the image.

image description

  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. image description
  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.
edit flag offensive delete link more

Comments

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.

Icetray gravatar imageIcetray ( 2014-09-19 08:16:34 -0600 )edit

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

Balaji R gravatar imageBalaji R ( 2014-09-19 08:28:18 -0600 )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?

Icetray gravatar imageIcetray ( 2014-09-19 08:45:56 -0600 )edit

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

Balaji R gravatar imageBalaji R ( 2014-09-19 09:01:44 -0600 )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.

Icetray gravatar imageIcetray ( 2014-09-19 20:33:40 -0600 )edit

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

Icetray gravatar imageIcetray ( 2014-09-21 07:40:31 -0600 )edit
0

answered 2014-09-18 10:19:10 -0600

thdrksdfthmn gravatar image

updated 2014-09-18 10:27:46 -0600

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.

edit flag offensive delete link more

Comments

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.

Icetray gravatar imageIcetray ( 2014-09-18 21:37:34 -0600 )edit

Question Tools

Stats

Asked: 2014-09-18 08:32:13 -0600

Seen: 1,091 times

Last updated: Sep 19 '14