I am calculating different attributes for connected regions of the image, with the final goal of classification. One of the attributes I am working with is a sparsity measure, calculated as the ratio of the area of the region (in pixels) and the area of the region's convex hull.

For now, I am doing this with OpenCV:

std::vector <cv::Point2f> region;
std::vector <cv::Point2f> convex_hull;
// fill the region ...
cv::convexHull(cv::Mat(region), convex_hull, false);

double ratio = (double)(region.size()) / std::abs(cv::contourArea(convex_hull));

The problems with this approach is that pixels are considered to have an area of 1 when calculating the region area, but are treated as points in convex hull calculation, causing disparity. An example would be a 4-pixel rectangle with the pixels coordinates ((1,1), (1,2), (2,1), (2,2)). Convex hull contains the same 4 points. But, the area of the region is calculated as 4 (counting the pixels), and the convex hull area as 1 (a 1x1 rectangle with corners in (1,1), (1,2), (2,1), (2,2)).

Can anybody suggest a way to compute these two areas in the same way, so that the range of my sparsity measure is in fact [0,1] and the region area never gets calculated as larger than convex hull area?

  • $\begingroup$ why not add the perimeter of the convex hull on top of its area? $\endgroup$ – Tolga Birdal Jul 17 '17 at 14:25
  • $\begingroup$ @TolgaBirdal If I did that (ignoring that I am trying to sum up area and length), the perimeter in the example I give of a 2x2 pixel rectangle is 4, and the convex hull area is calculated as 1; so I would get the total convex hull area as 4+1=5 (which is no more correct than 1...) $\endgroup$ – penelope Jul 17 '17 at 15:12
  • $\begingroup$ Sure, but isn't that an edge case? Maybe you could compute and see if that bias is systematic. If so, you could offset that amount. $\endgroup$ – Tolga Birdal Jul 17 '17 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.