Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a color palette image from a list of RGB color

I use color thief to extract a color palette from an image.

How to create an image of rgb value as a Palette?

from colorthief import ColorThief
color_thief = ColorThief('C:\Users\username\Desktop\index.jpg')
# get the dominant color
dominant_color = color_thief.get_color(quality=1)
print dominant_color
# build a color palette
palette = color_thief.get_palette(color_count=2)
print palette

Output:

(82, 129, 169)
[(82, 129, 169), (218, 223, 224), (147, 172, 193), (168, 197, 215), (117, 170, 212)]

The expected output is similar to http://www.color-hex.com/color-palette/895, i.e. a series of colored rectangles

like image 669
Programmer_nltk Avatar asked Dec 03 '25 09:12

Programmer_nltk


1 Answers

A solution using imshow from Matplotlib:

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

palette = [(82, 129, 169), (218, 223, 224), (147, 172, 193), (168, 197, 215), (117, 170, 212)]

palette = np.array(palette)[np.newaxis, :, :]

plt.imshow(palette)
plt.axis('off')
plt.show()

gives:

result image

like image 136
xdze2 Avatar answered Dec 05 '25 02:12

xdze2



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!