Programmer_nltk
Programmer_nltk

Reputation: 915

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

Upvotes: 3

Views: 3614

Answers (1)

xdze2
xdze2

Reputation: 4151

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

Upvotes: 6

Related Questions