2

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?

2
  • 4
    Any point is either going to be between two line segments, or outside. Knowing that you should be able to figure it out. It's not a hard problem. Jun 6, 2015 at 19:42
  • 2
    The page linked in that answer is archived here.
    – Kkelk
    Jun 6, 2015 at 19:46

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.