1

I ran into a problem that I don't know how to address, if anyone has any ideas I would be very grateful. So I have a NxM matrix and number of points (minimum 4) that represent a shape resting on the matrix as show in the figure (Each point is represented by a number, ignore the black/white points):

the boundaries of the shape

I know how to match each point to the x,y coordinate inside the matrix. But let's say I want to calculate the average of the values inside the polygon, how can I do it? Many thanks to all the helpers

I tried to parametrize the polygon to a new square, but without success...

Doron bs
  • 11
  • 1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Oct 29 '22 at 13:35

1 Answers1

0

You need to use a polygon filling algorithm (also called scan conversion). In a nutshell, you intersect the polygon with all horizontals through the matrix rows and find intervals covered by the inside of the polygon. Accumulate the matrix values spanned by these intervals.