[英]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? 如何创建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
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 , ie a series of colored rectangles 预期的输出类似于http://www.color-hex.com/color-palette/895 ,即一系列彩色矩形
A solution using imshow
from Matplotlib: 使用
imshow
的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();
gives: 得到:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.