pil, histogram, mask

Daniel Nogradi nogradi at gmail.com
Wed Jan 31 18:23:18 EST 2007


How does one do a histogram on only a part of an image?
This is what I found in the PIL documentation about histogram( ):

"""
im.histogram(mask) => list

Returns a histogram for those parts of the image where the mask image
is non-zero. The mask image must have the same size as the image, and
be either a bi-level image (mode "1") or a greyscale image ("L").
"""

But I don't quite understand what "mask image is non-zero" mean. Does
it mean non-white? For instance how would I get a histogram from the
border of an image where the border is, say, 5% in width and height of
the width and heigth of the full image? Do I need to prepare a mask
image that is white in the middle and non-white at the edges? I should
maybe add that I don't need the histogram really, only the mean color
value, but as far as I can see the 'mean' attribute only applies to an
image and a mask can not be specified.

In case I overlooked something in the docs (which is easily possible)
please point me to the appropriate page.



More information about the Python-list mailing list