title: python: turn polygon into mask array
body: <p>I have a polygon which I want to turn into a mask array, such that all points that fall inside/outside the polygon are True/False. I thought I found the perfect solution (<a href="https://stackoverflow.com/questions/3654289/scipy-create-2d-polygon-mask">SciPy Create 2D Polygon Mask</a>), but for some reason this doesn't work!</p>
  
  <p>What am I doing wrong?</p>
  
  <pre><code>#!/usr/bin/env python3
  
  import numpy as np
  import scipy as sp
  from PIL import Image, ImageDraw
  
  nx, ny = 10, 10
  
  poly = np.array([(1, 1), (6, 2), (9, 9), (3, 7)])
  
  img = Image.new("L", [nx, ny], 0)
  ImageDraw.Draw(img).polygon(poly, outline=1, fill=1)
  mask = np.array(img)
  
  print(mask)
  # [[1 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]]
  </code></pre>
  
  <hr>
  
  <p>Broader context:
  I'm working with features of arbitrary shape on a rectangular grid. I have the indices of all boundary points on the grid, and I want the indices of a convex hull around this feature. <code>scipy.spatial.ConvexHull(boundary_points)</code> gives me the edge points of the convex hull, and it is this hull polygon that I now want to turn into a mask.</p>