从RGB颜色列表创建调色板图像

时间:2018-08-07 14:14:33

标签: python image numpy

我使用color thief从图像中提取调色板。

如何将rgb值的图像创建为调色板?

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

输出:

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

预期输出类似于http://www.color-hex.com/color-palette/895,即一系列彩色矩形

1 个答案:

答案 0 :(得分:1)

使用Matplotlib中的imshow的解决方案:

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();

给予:

result image