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?

Community
  • 1
  • 1
Luke Taylor
  • 8,631
  • 8
  • 54
  • 92
  • 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. – Mark Ransom Jun 06 '15 at 19:42
  • 2
    The page linked in that answer is [archived here](https://web.archive.org/web/20130125232758/http://wiki.processing.org/w/Find_which_side_of_a_line_a_point_is_on). – Kkelk Jun 06 '15 at 19:46

1 Answers1

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.

Luke Taylor
  • 8,631
  • 8
  • 54
  • 92