从图像中提取颜色。使用CIE76公式根据视觉相似性对颜色进行分组。

extcolors的Python项目详细描述


从图像中提取颜色的命令行工具。 结果将以文本和图像两种格式显示。

文本结果将提供每种颜色在像素数和百分比中的使用情况。 而图像将为视觉表示提供调色板。

1   Installation

1.1   Package

$ pip install extcolors

1.2   Manually

  1. 以zip格式下载存储库。

  2. 将zip解压到文件夹中。

  3. 输入文件夹。

  4. 运行以下命令:

    $ pip install .
    

2   Usage

2.1   Input - Console

要使用应用程序,请提供应用程序应从中提取颜色的图像的路径。 在下面的示例中,图像位于执行命令的文件夹中,图像的名称为gameboy.png

$ extcolors gameboy.png

在本例中,gameboy.png引用以下imageRebecca Machamer创建。

http://cairns.se/extcolors/gameboy.png

2.2   Input - Script

要使用应用程序,请提供应用程序应从中提取颜色的图像的路径。 在下面的示例中,图像位于执行命令的文件夹中,图像的名称为gameboy.png

>>>importextcolors>>>colors,pixel_count=extcolors.extract("gameboy.png")>>>print(colors)[((0,172,170),386062),((245,245,245),59559),((82,90,92),17824),((102,184,52),15080),((236,27,111),1302),((255,180,0),137),((241,148,185),36)]

2.3   Output - Text

当应用程序完成时,它将输出有关执行的信息。 最相关的信息可能是包含提取的颜色的[RESULT]-部分 rgb值及其发生率以百分比表示。

基于gameboy.png

的输出
Extracted colors:
(0, 172, 170)  :  80.43% (386062)
(245, 245, 245):  12.41% (59559)
(82, 90, 92)   :   3.71% (17824)
(102, 184, 52) :   3.14% (15080)
(236, 27, 111) :   0.27% (1302)
(255, 180, 0)  :   0.03% (137)
(241, 148, 185):   0.01% (36)

Pixels in output: 480000 of 480000

2.4   Output - Image

应用程序完成后,它还将在执行命令的目录中创建一个映像。 图像将包含提取的颜色,这些颜色根据它们的出现率进行排序,从左到右换行。 图像将使用原始图像的名称,并附加执行时的时间戳。

基于gameboy.png

的输出 http://cairns.se/extcolors/gameboy-result-default.png

3   Additional Options

从命令行参数extcolors --help生成的输出。

usage: extcolors [-h] [--version] [-t [N]] [-l [N]] PATH

Extract colors from a specified image. Colors are grouped based on visual
similarities using the CIE76 formula.

positional arguments:
  PATH

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -t [N], --tolerance [N]
                        group colors to limit the output and give a better
                        visual representation. Based on a scale from 0 to 100.
                        Where 0 won't group any color and 100 will group all
                        colors into one. Defaults to 32
  -l [N], --limit [N]   upper limit to the number of extracted colors
                        presented in the output
  -o {all,image,text}, --output {all,image,text}
                        format(s) that the extracted colors should presented
                        in

4   Known Issues

4.1   Performance

当图像包含大量不同颜色时(大多数情况下都是这样),性能会减慢到停止状态。 如果不需要/不需要颜色分组,则解决方法是将公差级别设置为零。 将公差设置为零将使应用程序跳过正在进行的任何比较和 变成一个简单的计数器,产生更大的速度。

例如,一幅包含340K种独特颜色的图像(3840x2160)需要两个小时才能完成 公差等级为32(默认值)。但是,如果公差级别为零,则需要10秒。

4.2   Adobe RGB Color Space Not Supported

当前,转换为CIE L*A*B*时仅支持SRGB颜色空间。 这意味着分组的颜色可能不像预期的那样视觉匹配。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何定制springdata存储库方法名称?   html有没有办法将java应用程序或JApplet嵌入到网站中?   Jackson ObjectMapper将java从字符串序列化为JSON作为namevalue   java刷新JTable?   用Java程序分发用JavaDB制作的数据库   java Android如何启动新活动   当集合大小超过500.000时,java的处理速度会显著降低   在java的分层目录中的多个目录中查找相同的文件   java如何将ArrayList数据插入数据库   java如何修改此代码,使其时间复杂度为o(logn)或o(n),而不是o(n^2)   java面板(SimplePanel)中仅显示图像的前1/3(大约),   jakarta ee Java Bean和企业Java Bean之间的区别?   创建AWS Cloudfront自签名URL(java sdk)时出现amazon web服务错误   基于Jersey和Jackson查询参数的java动态属性过滤