Pro*_*ltk 3 python numpy image
我使用颜色窃贼从图像中提取调色板。
如何创建一个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
Run Code Online (Sandbox Code Playgroud)
输出:
(82, 129, 169)
[(82, 129, 169), (218, 223, 224), (147, 172, 193), (168, 197, 215), (117, 170, 212)]
Run Code Online (Sandbox Code Playgroud)
预期输出类似于http://www.color-hex.com/color-palette/895,即一系列彩色矩形
imshow使用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()
Run Code Online (Sandbox Code Playgroud)
给出: