c++ - How to determine the area of a polygon in an Image -
if having convex polygon vertices, area calculation in image not coming accurate standard formula.
(for simiplicity) if having 3x3 square, , vertices (1,1) (1,3) (3,3) (3,1)
by polygon area calculation method depicted here
and dividing summation 2 area.
so 3 x 3 data above, we'll area 4 instead of 9.
this happening because vertices not points pixel.
this corresponding code. coordinates cyclic.
int x[] = { 1, 1, 3, 3, 1}; int y[] = { 1, 3, 3, 1, 1}; double sum1 = 0; double sum2 = 0; int numelements = 5; (int k = 0; k < numelements-1; k++) { sum1 += x[k] * y[k + 1]; sum2 += y[k] * x[k + 1]; } double area = std::abs((double)(sum1 - sum2))/2;
for square, can +1 width , height , area correct. irregular polygons in image? hope question makes sense.
if don't want work pixel corners vertices, consider next method (works simple figures - convex ones, concave ones):
add additional fake pixel @ right side of every right-border pixel, @ bottom side of every bottom-border pixel, @ right-bottom of right-bottom corner pixel. here gray pixels initial, light blues ones - fake.
Comments
Post a Comment