Ask Your Question
0

Convex Hull for Added Contours

asked Sep 18 '14

Icetray gravatar image

updated Sep 19 '14

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?

Preview: (hide)

Comments

Can you explain it with a picture?

Balaji R gravatar imageBalaji R (Sep 18 '14)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 (Sep 18 '14)edit

2 answers

Sort by » oldest newest most voted
1

answered Sep 19 '14

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.
Preview: (hide)

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 (Sep 19 '14)edit

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

Balaji R gravatar imageBalaji R (Sep 19 '14)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 (Sep 19 '14)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 (Sep 19 '14)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 (Sep 20 '14)edit

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

Icetray gravatar imageIcetray (Sep 21 '14)edit
0

answered Sep 18 '14

thdrksdfthmn gravatar image

updated Sep 18 '14

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.

Preview: (hide)

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 (Sep 19 '14)edit

Question Tools

Stats

Asked: Sep 18 '14

Seen: 1,161 times

Last updated: Sep 19 '14