[Image-SIG] Problems with polygon drawing

Andrew Mark andrew.mark at is.mpg.de
Fri Aug 23 10:05:04 CEST 2013


I'd like to use PIL to rasterise a polygon, but I'm having trouble getting even a simple test to work. I expect the following to produce a 11x11 array with a white diamond on a black background, but I only get the background. 

diamond = array([[5,0], [10,5], [5,10], [0,5]])
img = Image.new('L', (11,11), 0)
draw = ImageDraw.Draw(img)
draw.polygon(diamond, fill=1, outline=1)
array(img)

array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)

The method draw.line() works as it should. What am I doing wrong?

Thanks,

-AM


More information about the Image-SIG mailing list