Ask Your Question

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

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 close merge delete

## 1 answer

Sort by ยป oldest newest most voted

contourArea() uses Green formula (http://en.wikipedia.org/wiki/Green'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.

more

Official site

GitHub

Wiki

Documentation

## Stats

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

Seen: 4,390 times

Last updated: Jul 04 '12