Using images as data, I built a pipeline to extract dominant colors from urban photography and aggregate them into city-level palettes of 6 colors each.
The dataset: 1,800 images across 12 cities.
How does this work?
Using a single image from Tokyo, let me walk you through exactly what the algorithm does.
sensoji_temple_001.jpg
360,000 pixels
Each pixel = (R, G, B)
Pixels plotted in "color space"
Step 1: Everything in one box
Step 2: Cut along biggest range
Step 3: Repeat until we have 6 distinct boxes
One image's palette
6 colors extracted
This is Sensoji Temple in Tokyo, with red lanterns, wooden beams, and crowds of visitors.
Zoom in far enough, and any photo becomes a grid of tiny colored squares. A 600×600 image has 360,000 pixels.
How do we simplify 360,000 colors down to just 6?
Every color is stored as (R, G, B) — how much red, green, and blue light it contains.
(201, 70, 61) = The red lantern
(26, 58, 74) = The shadowy blue
Imagine a 3D box where X = red, Y = green, Z = blue. Every pixel becomes a point in this space.
Therefore, similar colors cluster together.
Median Cut, used by the ColorThief library, starts by putting all pixels into a single, merged container.
Find which color channel (R, G, or B) has the biggest range. This is the axis (R,G, or B) along which there is the largest (minimum-maximum) value. Cut the box in half along that axis at the median.
From the resulting two boxes, take the box with the most variation and cut it along the median again, increasing the number of boxes by 1 each time.
The algorithm repeats until we have 6 boxes, and the average color of each box becomes one of the six final palette colors.
From 360,000 pixels down to 6 representative colors of a single image. This is a single image's color palet
Post-processing filters out very dark and gray colors from sidewalks, roads, and concrete to focus on more vibrant essence.
How do we aggregate this for a whole city?
I'll use Tokyo as an example. I extracted colors from 150 photographs, which included temples, streets, neon signs, markets, and trains.
150 images from Tokyo × 6 colors extracted from each = 900 total colors. Here are some example palettes from other images:
I then clustered similar colors, and found the most frequently appearing, or dominant colors:
A palette representing temples, lanterns, night lights, and wooden architecture
This way, outlier photos don't skew results so that the palette reflects what's consistently present.
After analyzing 1,800 photographs across 12 cities, here's what the algorithm found.
Thailand
Warm reds and golds from temples, markets, and night markets
Morocco
Teal tiles, terracotta architecture, spice market coral
Singapore
Tropical green, glass towers, Marina Bay blue
Greece
Aegean blues, iconic whitewash
Brazil
Jungle greens and bright carnival colors
Australia
Earthy olive greens and laneway street art
Mexico
Creamy neutrals, clay earth, and terracotta
India
Sky blue and palace-pink sandstone tones
Cuba
Teals, warm ochre, and coastal pastel
Denmark
Frosted blues, soft lavender, and muted hygge warmth
Turkey
Bosphorus blues meet bazaar gold
Japan
Vermillion accents over warm wood and night lights
Patterns from comparing the 12 cities side by side.
"Warm" and "cool" are perceptual qualities that I attempted to approximate mathematically. Since warm colors (red, orange, yellow) have high R values and cool colors (blue, cyan) have high B values:
temperature = (R - B + 255) / 510 × 100For each palette, I averaged the temperature of all 6 colors, with Green as roughly neutral benchmark (~50).
Cities ranked by average color temperature
Bangkok and Santorini are the warmest and coolest cities in the dataset.
Melbourne and Rio show what two palettes with the same color temperature (exactly 62°) can look like.
Santorini is the only city with a nearly single-hue palette - 5/6 colors are variations of blue.
Tokyo and Mexico City form the algorithm's most similar pair despite different climates and locations. Both built from warm earth tones, vermillion, and terracotta.
Bangkok's palette averages 79% saturation, while Copenhagen sits at the opposite end, at 41%. Tropics versus the Nordic climate.
Singapore is the only city where green is the dominant hue. Garden City lives up to its name, with hints of the blue glass buildings in the skyline.
I was expecting grey concrete and glass. Instead, the algorithm found something different. Upon analyzing the photos, here's what I think the colors represent:
The city's most photographed icons, along with the glass & concrete skyline, are 19th century brick, yellow cabs, and the deep greens of Central Park.