472,127 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

pil, histogram, mask

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.
Jan 31 '07 #1
2 4178
Daniel Nogradi
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.
You can slice parts of the image, and then use the
ImageStat.Stat(im).mean
On it.

Bye,
bearophile

Feb 1 '07 #2
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.

You can slice parts of the image, and then use the
ImageStat.Stat(im).mean
On it.

Bye,
bearophile
Okay, I'll try that, thanks a lot.
Feb 1 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Oracle3001 | last post: by
1 post views Thread by bleh | last post: by
1 post views Thread by Andre | last post: by
27 posts views Thread by ext_u | last post: by
12 posts views Thread by KraftDiner | last post: by
5 posts views Thread by arnuld | last post: by
1 post views Thread by avenger3200 | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.