November 2, 2018

Color Histograms for Photo Galleries

Today I have a day off and … well, I got bored pretty quick. For whatever reason, my brain spat out the idea to write a little program that computes something like histograms of photo galleries of my past trips.

This means: the program loops through photos of a gallery sorted by date and time, determines the most dominant color in the current image and draws a line in that color. So you end up with some kind of histogram that nicely reflects the “mood” of the gallery (and the entire holiday).

# -*- coding: utf-8 -*-

from colorthief import ColorThief
from glob import glob
from PIL import Image, ImageDraw

def getImages(path):
    return glob(path)

def getDomCol(image):
    color_thief = ColorThief(image)
    return color_thief.get_color(quality=10)

# get all images
images = getImages("path/to/images/*.jpg")
images = sorted(images)

# amount of lines
n = len(images)
# hight of histogram
h = 100
# current line
c = 0

# new canvas
im ="RGB", (n, h), color=0)

# loop through gallery
for image in images:
    # get dom. color
    col = getDomCol(image)
    # draw line
    draw = ImageDraw.Draw(im)
    draw.line((c, 0, c, h), fill=col, width=1)
    c = c + 1"histogram.png")

I found the histogram of the latest trip to Sicily pretty interesting:

See all that dreary beige colors? That’s a quite long period of hazy sky combined with towns/archaeological sites built of sandstone.

North Italy: Better weather, more contrast, more colors

Sardegna: lots of blue sky and the ocean

South Tirol:


Portugal North: a lot of hiking in woods

Portugal South:




© ho1ger 2015 - 2022