How can polygon vertices become a filled training mask?

polygon connects successive vertices and closes the last edge. Its fill value labels the interior.

Pixel experiment and interpretation

Three vertices enclose a triangle. Probe an interior point and a clear exterior point to catch an outline-only annotation.

from PIL import Image, ImageDraw

im=Image.new('L',(6,6))
ImageDraw.Draw(im).polygon([(0,0),(5,0),(0,5)],fill=7)
(im.getpixel((1,1)),im.getpixel((5,5)))

Result (7, 0)

中文

如何把多边形顶点列表变成实心训练掩膜?

polygon 连接相邻顶点并闭合末端,fill 控制内部像素的取值。

像素实验与适用边界

三个顶点圈出一片三角区域。用内部点和明显的外部点做测试,比只检查边框更能发现漏填。

from PIL import Image, ImageDraw

im=Image.new('L',(6,6))
ImageDraw.Draw(im).polygon([(0,0),(5,0),(0,5)],fill=7)
(im.getpixel((1,1)),im.getpixel((5,5)))

结果 (7, 0)

References / 参考来源

Keep reading / 继续阅读