从RGB列表创建调色板图像

2024-09-28 05:19:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用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

输出:

^{pr2}$

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


Tags: from图像importgetusernamergbuserscolor
1条回答
网友
1楼 · 发布于 2024-09-28 05:19:47

使用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

相关问题 更多 >

    热门问题