Created
March 27, 2017 02:50
-
-
Save dyspop/77b220a38e4309326bdf802ac9ac1b64 to your computer and use it in GitHub Desktop.
assign averages of image channel histograms to a dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
filename = 'pastries.jpg' | |
image = Image.open(filename) | |
# get average color | |
# inspiration from https://gist.github.com/olooney/1246268 | |
def average_image_color(imagedata): | |
channel_histograms = {} | |
color_averages = {} | |
for mode in imagedata.mode: | |
channel_histograms[mode] = channel_histogram(imagedata,mode) | |
color_averages[mode] = sum( i*w for i, w in enumerate(channel_histograms[mode]) ) / sum(channel_histograms[mode]) | |
return color_averages | |
print average_image_color(image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got this error:
channel_histogram is not defined
.What is channel_histogram?