你能定义“前 5 种主色”吗?我认为这并不像听起来那么容易...
访问您为Embed.ly和Color Thief对您的测试图像的解释提供的链接时,可以看到不同的结果清楚地表明了这一点。
嵌入
下面是 Embed.ly 列出的 5 种提取颜色(我查看了页面的 HTML 源代码以找出答案):
rgb(13, 28, 37)
rgb(44, 74, 94)
rgb(71, 112, 131)
rgb(105, 147, 163
rgb(198, 209, 216)
使用 ImageMagick 创建具有以下 5 种颜色的调色板:
convert \
-size 60x60 \
label:" Embed.ly" \
xc:"rgb(13, 28, 37)" \
xc:"rgb(105, 147, 163" \
xc:"rgb(71, 112, 131)" \
xc:"rgb(44, 74, 94)" \
xc:"rgb(198, 209, 216)" \
+append \
embedly-palette-from-testimage.jpg
看看结果:

颜色小偷
Color Thief 将一种颜色命名为“主要”颜色:
rgb(21, 30, 38)
Color Thief 还列出了另外 9 种颜色的调色板(同样是从 HTML 源代码中检索的值):
rgb(18, 27, 35)
rgb(100, 142, 164)
rgb(51, 84, 110)
rgb(32, 53, 74)
rgb(47, 46, 43)
rgb(83, 85, 76)
rgb(145, 143, 128)
rgb(106, 141, 140)
rgb(62, 84, 81)
使用 ImageMagick 创建具有 Color Thief 的 9 种调色板颜色的调色板:
convert \
-size 60x60 \
label:" Color Thief" \
xc:"rgb(18, 27, 35)" \
xc:"rgb(100, 142, 164)" \
xc:"rgb(51, 84, 110)" \
xc:"rgb(32, 53, 74)" \
xc:"rgb(47, 46, 43)" \
xc:"rgb(83, 85, 76)" \
xc:"rgb(145, 143, 128)" \
xc:"rgb(106, 141, 140)" \
xc:"rgb(62, 84, 81)" \
+append \
ct-palette-from-testimage.jpg
看看结果:

颜色小偷是基于quantize.js
. 它使用提供的中值切割算法quantize.js
对相似的颜色进行聚类,然后从最大的聚类中返回基色作为“主导”颜色。
它如何确定将哪些颜色作为“调色板颜色”返回可以从其托管在 Github 上的源代码中确定。
ImageMagick 的 5 种量化颜色
您的问题仅在将图像量化为 5 种颜色后列出了 ImageMagick 直方图的输出。
使用这 5 种颜色来创建另一个调色板:
convert \
-size 60x60 \
label:" ImageMagick" \
xc:"srgb(19,28,35)" \
xc:"srgb(79,88,84)" \
xc:"srgb(44,77,103)" \
xc:"srgb(27,51,77)" \
xc:"srgb(84,126,150)" \
+append \
im-palette-from-testimage.jpg
看看结果:

比较 3 个调色板
使用此命令创建 3 个调色板的视觉比较:
convert \
ct-palette-from-testimage.jpg \
embedly-palette-from-testimage.jpg \
im-palette-from-testimage.jpg \
-append \
color-palettes.jpg
结果:

可以清楚地看到,Color Thief 和 ImageMagick 直方图中的 5 种量化颜色都没有包含 Embed.ly 返回的相当明亮的第 5 种颜色。
再次与您的测试图像进行比较:

“使用更大的调色板然后只选择前 n 个颜色会更好吗?”
你为什么不测试它并找出你自己呢?