def get_mask(self, fill=1, outline=0):
"""
Get a mask that is nonzero within the object.
:param fill: A color to use on the object's interior
:param outline: A color to use on the object's edge (single pixel)
:return: A 2D numpy array of uint8
"""
if self.type in (TYPE_POLYGON, TYPE_BOUNDING_BOX):
(top, left, bottom, right) = self.polygon.bounds()
w = right-left
h = bottom-top
mask = Image.new("I", (w, h))
d = ImageDraw.Draw(mask)
d.polygon([(px-left, py-top) for (px, py) in self.polygon.points],
fill=fill, outline=outline)
del d
return np.asarray(mask)
else:
assert False, "Unhandled Type"
评论列表
文章目录