Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Selecting a feature with many internal edges on a solid background

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.