Ask Your Question

Which is more efficient, use contourArea() or count number of ROI non-zero pixels?

asked 2012-07-03 07:59:28 -0600

Rui Marques gravatar image

updated 2012-07-03 09:25:02 -0600

In a case were you only want relative areas, which one is faster to compute: calculate a contour area - contourArea() - or count the number of ROI non-zero pixels?

You can assume the contours have been found and you have everything needed to do either case.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-07-04 08:56:49 -0600

Vadim Pisarevsky gravatar image

contourArea() uses Green formula ('stheorem) to compute the area, therefore its complexity is O(contournumberofvertices). Counting non-zero pixels in the ROI is O(roiwidth*roiheight) algorithm, i.e. much slower. Note, however, that because of finite, and quite low, resolution of the raster grid, the two algorithms will give noticeably different results. For large and square-like contours the error will be minimal. For small and/or oblong contours the error can be quite large.

edit flag offensive delete link more

Question Tools


Asked: 2012-07-03 07:59:28 -0600

Seen: 4,745 times

Last updated: Jul 04 '12