[Image-SIG] Choosing arbitrary polygons
Jeffrey Kunce
kuncej@mail.conservation.state.mo.us
Fri, 19 Apr 2002 10:34:20 -0500
> One of the most important things that I need
>to do is to select arbitrary areas of an image (polygons), and then
>extract statistics off that.
Here is some code that should give you some ideas
def PolygonHistogram(anImage, aPolygon):
'''computes the histogram of the portion of anImage within
aPolygon'''
mask = Image.new('1', anImage.size, 0)
draw = ImageDraw.Draw(mask)
draw.polygon(aPolygon, fill=1, outline=1)
return anImage.histogram(mask)
You can also do interesting things by using various ImageChops
operations on an image and a mask.
--Jeff