Find all points outside of a quadrilateral (not a rectangle)

294 views Asked by At

Question

I'm using PIL, and I have part of my code that requires finding which points are outside of a quadrilateral. If I have points like [(50, 20), (230, 40), (200, 190), (100, 200)], how can I quickly fill all the points outside this area with black?

I want a function like addBorder(points, img), where addBorder([(50, 20), (230, 40), (200, 190), (100, 200)], Image.open('lenna.png')) would return:

output

What I've Found so Far

This answer looked useful until I realized the link was dead. If anyone knows if the page linked in that answer still exists somewhere else, I'd love to see it. I tried a few algorithms before I realized that they only worked for rectangles.

Can anyone help me?

1

There are 1 answers

0
Luke Taylor On

I haven't found a way that doesn't involve checking every pixel, but I found my answer in rules for filling. I used the even-odd rule.