Dominant color in logos
A recent tweet from Rasmus Andersson (an ex-designer at Spotify who also made the first logo) had a pretty interesting reasoning behind the idea why Spotify's logo is green
I wanted to explore what's the current color palette of logos out there and see whether there is a gap in a particular color which could make a new logo more recognizable.
image_to_read = '/home/jovyan/work/5klogos/002192.png'
image_to_read_2 = 'https://i.stack.imgur.com/DNM65.png'
import cv2
import numpy as np
from skimage import io
from matplotlib import pyplot as plt
img = io.imread(image_to_read)[:, :]
plt.imshow(img, interpolation='nearest')
plt.show()
def getDominantColors(img):
average = img.mean(axis=0).mean(axis=0)
pixels = np.float32(img.reshape(-1, 3))
n_colors = 5
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, .1)
flags = cv2.KMEANS_RANDOM_CENTERS
_, labels, palette = cv2.kmeans(pixels, n_colors, None, criteria, 10, flags)
_, counts = np.unique(labels, return_counts=True)
return (palette, counts)
Helper to pair the counts with the colors
def pairCountsAndPalette(palette, counts):
countPaletteMap = {}
for count in counts:
if count not in countPaletteMap:
countPaletteMap[count] = palette[np.where(counts==count)]
return countPaletteMap
Filter out the white/black colors
palette, counts = getDominantColors(img)
countPalette = sorted(pairCountsAndPalette(palette, counts).items(), reverse=True)
dominantNonGrayColor = None
for count, color in countPalette:
meanColor = sum(color[0]) / len(color[0])
if meanColor > 5 and meanColor < 250:
dominantNonGrayColor = color[0]
break
from PIL import Image, ImageDraw
im = Image.new('RGB', (100, 100), color=(dominantNonGrayColor[0], dominantNonGrayColor[1], dominantNonGrayColor[2]))
im
Version done on a bigger scale
import glob
import math
logo_paths = glob.glob("./5klogos/*.png")[:400]
# image_to_read = '/home/jovyan/work/5klogos/002192.png'
# image_to_read_2 = 'https://i.stack.imgur.com/DNM65.png'
square_grid_size = int(math.sqrt(len(logo_paths)))
square_grid_size
background = Image.new('RGB', (square_grid_size * 32, square_grid_size * 32), 'white')
for i in range(len(logo_paths)):
current_row = math.floor(i / square_grid_size)
current_col = i % square_grid_size
logo_path = logo_paths[i]
img = io.imread(logo_path)[:, :]
offset = (current_col * 32, current_row * 32)
background.paste(Image.fromarray(img, 'RGB'), offset)
background
background_res = Image.new('RGB', (square_grid_size * 32, square_grid_size * 32), 'white')
for i in range(len(logo_paths)):
logo_path = logo_paths[i]
img = io.imread(logo_path)[:, :]
getDominantColors(img)
# Get dominant palette
palette, counts = getDominantColors(img)
countPalette = sorted(pairCountsAndPalette(palette, counts).items(), reverse=True)
dominantNonGrayColor = None
for count, color in countPalette:
meanColor = sum(color[0]) / len(color[0])
if meanColor > 5 and meanColor < 250:
dominantNonGrayColor = color[0]
break
current_row = math.floor(i / square_grid_size)
current_col = i % square_grid_size
offset = (current_col * 32, current_row * 32)
if dominantNonGrayColor is not None:
dominant_color_image = Image.new('RGB', (100, 100), color=(dominantNonGrayColor[0], dominantNonGrayColor[1], dominantNonGrayColor[2]))
background_res.paste(dominant_color_image, offset)
background_res