Ask Your Question

Selecting a feature with many internal edges on a solid background

asked 2013-09-11 19:07:35 -0600

virnovus gravatar image

I'm writing software to automatically center and crop pictures of objects taken on a solid background. The objects tend to have many internal edges and very well-defined outer edges. Nearly all of them are convex with simple geometry that can be expressed by ten or fewer straight lines and/or curves. Although the algorithm won't necessarily know exactly what shape these objects are, or how much they're rotated with respect to the photo's axes, they'll all be simple shapes like basketballs, cell phones, or books, and it's pretty safe to assume they're all convex, or very nearly convex.

So far, I've been most successful finding these shapes by using the Canny() feature detection method, which gets me a black and white image with all the edges highlighted. When I do this, perhaps 95% of the lines are part of the shape that I want, either inside the shape or highlighting its outside eges. Now, from here, what would be the best way to calculate a bounding box containing the largest simple, convex shape in the photo? Most of the bounding box type functions I've looked at seem to take a point set as input, but my data (after Canny) consists of many light-colored edges on a totally black background.

Anyway, I only need the dimensions for cropping purposes, so what would be the simplest, most reliable way I could get them, without also selecting the occasional small background object? Any help would really be appreciated.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-09-12 01:03:47 -0600

Moster gravatar image
edit flag offensive delete link more


Thanks. I've tried to do something similar, but I guess what I failed to mention is that the edges that are inside the object are often much higher-contrast than the object's outside edge. Imagine, say, a dull orange basketball with black seams, on a tan background. Although the edge detection can find the outside edges if it's set to be sensitive enough, it always picks up the seams first. I guess in this case, maybe I should just combine all the point arrays into one large point array, then find the bounding box for that? No matter what parameters I set, I typically have about 50 contours forming a cloud that very closely approximates the shape of my object. I'm sure there's a simple solution here...

virnovus gravatar imagevirnovus ( 2013-09-12 08:06:41 -0600 )edit

Question Tools


Asked: 2013-09-11 19:07:35 -0600

Seen: 598 times

Last updated: Sep 12 '13