Is it possible to find average color of an image from its histogram?
I took the average of each color by this method and wrote the average of red, green and 开发者_如何转开发blue to database.
Here are the images sorted by "-blue". As you can see the 5th image has the most blue. Am I doing something wrong, or is it not possible to get average color from the histogram?
This is the handler where I create the histogram:
class ImageSave(webapp.RequestHandler):
def post(self):
homepage = HomePage()
original_image = self.request.get("img")
url = self.request.get("url")
firm_name = self.request.get("firm_name")
original_image = db.Blob(original_image)
thumbnail = images.resize(original_image, 250, 250)
img = images.Image(thumbnail)
hist = img.histogram()
rgb_weighed_average = hist_weighed_average(hist)
#update database
homepage.original_image = original_image
homepage.thumbnail = thumbnail
homepage.firm_name = firm_name
homepage.url = url
homepage.red = rgb_weighed_average[0]
homepage.green = rgb_weighed_average[1]
homepage.blue = rgb_weighed_average[2]
homepage.put()
self.redirect("/imageupload")
Thanks!
Actually, the fifth image doesn't have the most blue. Note that white is (255, 255, 255)
as rgb, so an image that is completely white has just as much blue as an image that is completely blue. A darker blue has a smaller blue
component than white.
精彩评论