Extracting colour palettes from an image
Trying out Colorthief a python package extract colour palettes from an image.
Was reading through an enhancement request on Pillow's github page. Currently Pillow does not give an built-in way to identify all dominant colours on an image. The suggestion was to port "Colorthief" package into Pillow.
Trying Colorthief.
Fairly simple and direct, pip install it.
Follow the instructions here and with little bit of help on how to map numpy arrays it is easy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | from colorthief import ColorThief import numpy as np import matplotlib.pyplot as plt color_thief = ColorThief('/home/pk/Desktop/bd.png') dominant_color = color_thief.get_color(quality=1) """dominant_color 0 = 147 1 = 66 2 = 46""" color_palette = color_thief.get_palette(color_count=12) color_palette = np.asarray(color_palette)[np.newaxis, :, :] """ Color_palette = 0 = <numpy.array at 0x7f64b92173f0[6x1]> 0 = [136 53 35] 1 = [40 14 22] 2 = [195 117 89] 3 = [232 168 152] 4 = [213 130 107] 5 = [209 136 134]""" plt.imshow(color_palette); plt.axis('off'); plt.show(); |