Ask Your Question
2

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

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

Rui Marques gravatar image

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

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
6

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

Vadim Pisarevsky gravatar image

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.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

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

Seen: 1,822 times

Last updated: Jul 04 '12