I have following picture
which I extract the contour from. The contour looks like following
I am wondering, for any pixel in the image, how do I determine if it is inside the contour or not? Say "inside" here means any pixel in the body.
If possible, I'd prefer simple, direct, and elegant algorithm. Thanks.


Assuming that the contour doesn’t have any loops, shoot a ray in some convenient direction from the pixel to the edge of the image and count the number of times that it crosses the contour: an odd number of crossings means that it’s inside, an even number, outside. You’ll need to be a bit careful about how you count when the ray coincides with the contour for a while—there might not be an actual crossing in that case.