Determine If 2D Pixel Inside a Region Without Formula

316 Views Asked by At

I am trying to figure out if any given pixel is inside a region which is defined by other pixels, not a formula. In my case the pixels that define the region come from a projected ellipsoid, I could not find a formula that would allow me to run the test in 2D, so I have to run the test numerically. However the pixels that define the region have gaps - what to do in this situation? Should I interpolate in 2D, and shoot off rays in 4 directions to check intersections, or is there a more elegant approach?

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

Per @HenningMakholm's answer:

pts = [[182,250],[153,278],[149,309],[168,336],[198,309],[205,280],[198,263]]
pts = np.array(pts)
pt1 = np.array([180,280]) # inside 
a = pts - pt1
aa = a[:len(d),:]
d = np.diff(pts,axis=0)
print np.cross(aa,d)
pt2 = np.array([380, 280]) # outside
a = pts - pt2
aa = a[:len(d),:]
print np.cross(aa,d)