def getPolyIdxImg(corners,res,debug=False):
"""Returns all indices of image that lie within given polygon.
Args:
corners (list): List of (x,y)-coordinates of corners.
res (int): Resolution of image (e.g. 512).
Keyword Args:
debug (bool): Print debugging messages.
Returns:
tuple: Tuple containing:
* indX (list): List of indices inside polygon in x-direction.
* indY (list): List of indices inside polygon in y-direction.
"""
#Convert to np array if necessary
corners=np.asarray(corners)
#Define polygonial patch
poly = ptc.Polygon(corners,edgecolor='r',facecolor=(1,0,0,.2),)
#Create grid
x_int=np.arange(1,res+1,1)
y_int=np.arange(1,res+1,1)
g = np.meshgrid(x_int, y_int)
#Zip them into coordinate tuples
coords = list(zip(*(c.flat for c in g)))
#Check which point is inside
pts = np.vstack([p for p in coords if poly.contains_point(p, radius=0)])
indX,indY= pts[0,:],pts[1,:]
return indX,indY
评论列表
文章目录