If the border is formed by segments and you can code it as the sequence of edges
( (P0x, P0y), (P1x, P1y), ... , (P0x, P0y) ),
then there is a simple way to compute the inside area:
This is simply the integral of the segments (the area of the underlying trapeziums), with a positive sign when going right and negative when going left. In order for it to give the correct (positive) result, the points of the border must be stored clockwise. If there are holes in your image, you have to compute their area separately and subtract it from the area of the outer image (or you could use other tricks, like inserting a "cut" from the outer border to the inner one and counting it in both directions).my @border = ( [2,1], [1,4], [4,5], [5,2], [2,1] ); my $area = 0; for ( 0 .. $#border-1 ) { $area += ( $border[$_+1][0] - $border[$_][0] ) * ( $border[$_][1] + $border[$_+1][1] ) / 2; } print "$area\n";
Cheers
AntonioIn reply to Re: pixel counting
by abell
in thread pixel counting
by redbeard
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |