python颜色参数palette_PyColorPalette 能够通过K均值聚类过程从给定图像中提取主要颜色或特定索引处的颜色列表...

PyColorPalette

PyColorPalette is a Python 3 tool capable of pulling a list of the top colors, or the color at a specific index, from a given image through the process of K-means clustering. Images can be provided either through a direct path or from a URL. Along with the RGB/Hex color value, you have the option to also retreive the percentage of the image that specific color takes up.

See examples below!

Usage

PyColorPalette derives a color palette using K-means clustering to create a cluster map. To see the cluster map use show_clustering=True. (Thank you, ZeevG)

from PyColorPalette import ColorPalette

pal = ColorPalette(r"/Users/user/Pictures/my_image.png", show_clustering=False)

#Use a raw string for Windows paths.

print(pal.get_top_colors(n=5, ratio=False, rounded=True))

# [(251, 243, 230), (101, 50, 81), (59, 18, 48), (58, 17, 47), (60, 19, 49)]

print(pal.get_color(index=3, ratio=True, rounded=True))

# ((58, 17, 47), 14)

'''

Retrieve values in hex.

'''

print(pal.get_color(index=3, ratio=True, to_hex=True, rounded=False))

# ('#3a112f', 14.1953125)

Examples

Dependencies

PyColorPalette uses the Python Imaging Library (PIL) and numpy. To Install:

pip install Pillow

pip install numpy

(Pillow and PIL cannot co-exist in the same environment. Before installing Pillow, please uninstall PIL if previosuly installed.)

Installation

pip install PyColorPalette

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值