如何检测图像上是否存在着色或着色?

时间:2016-02-11 00:31:13

标签: javascript colors imagemagick node-imagemagick

我想计算图像上可用于丝网印刷的纯色,并限制每种设计最多10种颜色,例如teespring。{/ p>

我尝试过多种技术来使用javascript(colorthief)和imagemagick计算独特的颜色。但是,结果不适用于此目的,因为它还考虑了着色或着色中存在的所有颜色。

enter image description here

上面的图片示例,colorthief返回9种独特的颜色。但如果将限制设置为100,则返回如下。

var palette = colorThief.getPalette(image, 100);

enter image description here

所以我想知道如果它的颜色少于10种,如何检测设计?

1 个答案:

答案 0 :(得分:0)

我无法从你的问题中看出你是喜欢还是不喜欢teespring或ColorThief做什么或问题是什么,或者为什么要求100种颜色,或者你认为100种颜色是错误的,或者对...所以我会尝试建议获取颜色的方法,你可以看看你是否喜欢它们。当您对其他工具持开放态度时,我会选择适用于OSX,Linux和Windows的ImageMagick。

因此,从您的图像开始,您可以在命令行中询问ImageMagick,选择其中10种最佳颜色的概念,然后将它们制作成仅使用这些颜色的样本,并将其从10px调整为1px到500像素,你可以看到它:

convert motor.png -colors 10 -unique-colors -scale 500x swatch.png

enter image description here

或者,您可以在YIQ颜色空间中对ImageMagick进行量化,如下所示:

convert motor.png -quantize YIQ -colors 10 -unique-colors -scale 500x swatch.png

enter image description here

或者,如果您希望颜色选择算法在选择颜色时忽略饱和度的变化,您可以转到HSL颜色空间并将饱和度固定在50%,使色相和亮度不受影响,然后返回RGB色彩空间并选择颜色如上,但现在有固定的饱和度:

convert motor.png -colorspace hsl -channel G -fx 0.5 +channel -colorspace RGB -colors 10 -unique-colors -scale 500x swatch.png

enter image description here