算法设计:为最突出的色彩图像量化算法、最突出、图像、色彩

2023-09-11 04:13:19 作者:若不爱,一切都能成为借口

所以我工作的一个方法来提取主色的所认为的从图像人类的。

So I'm working on a way to extract dominant colors as perceived by humans from an image.

作为一个例子,这里有一张照片:的https://500px.com/photo/63897015/looking-out-for-her-kittens-by-daniel-paulsson

As an example, here's a photo: https://500px.com/photo/63897015/looking-out-for-her-kittens-by-daniel-paulsson

大多数人会认为显性的颜色是刺入眼睛的蔚蓝色。使用标准的量化,但是,蓝色完全消失,当你低于16色左右。眼睛只占用了画布的0.2%,所以要对于一般不工作的。

Most humans would think the 'dominant' color is that piercing azure of the eyes. Using standard quantization, however, that blue disappears completely when you drop below 16 colors or so. The eyes only take up 0.2% of the canvas, so going for the average doesn't work at all.

项目详情:我建立一个Rails应用程序,将接受上载的照片或一个特定的颜色,并返回一堆其他的照片相似的主色。该工具将被用于设计人员发现,摄影,符合他们的pre-现有的配色方案。还有其他一些很酷的想法我也一样,如果我能得到的技术位整理出来。

Project Details: I'm building a Rails app that will accept an uploaded photo or a specific color, and will return a bunch of other photos with similar dominant colors. The tool will be used by designers to find stock photography that matches their pre-existing color scheme. There are other cool ideas I have, too, if I can get the technical bit sorted out.

当前研究:我已经花了过去24小时内看完所有的这些东西。所有我试过的服务,TinEye是唯一一个不正确的,但他们是封闭源代码。我无法提供超过1个链接,但你可以谷歌TinEye色彩来找到它。

Current Research: I've spent the last 24 hours reading all about this stuff. Of all the services I've tried, TinEye is the only one that does it properly, but they're closed source. I can't provide more than 1 link, but you can google 'TinEye Color' to find it.

工具使用:我使用ImageMagick做图像转换,并生成柱状图

Tools Used: I'm using ImageMagick to do the image conversion and histogram generation.

所需的结果:当给定的那张照片,我想创建5-6颜色的调色板,与饱和的蔚蓝是其中之一

Desired Result: When given that photo, I'd like to create a palette of 5-6 colors, with that saturated azure being one of them.

电流法:我现在做的方式是我将其降低到32或64种颜色,并寻找饱和度/色调异常值。如果标准偏差低,离群是显著远,我将它添加到调色板。然后,我将照片进一步减少到4种颜色,并结合他们5-6调色板。

Current Method: The way I'm doing it now is I reduce it to 32 or 64 colors, and look for saturation/hue outliers. If the standard deviation is low and the outlier is significantly far away, I'll add it to the palette. Then I'll further reduce the photo to 4 colors and combine them for a 5-6 color palette.

我的提问:我的问题是与ImageMagick的的量化算法。我不想拿颜色的平均水平,我想向他们喜欢的颜色组,走位,有利于饱和的色彩。当我减少猫图片32色,眼睛都被转换为一个非饱和灰色。

My Question: My problem is with ImageMagick's quantization algorithm. I don't want to take the average of the colors, I want to group them by like colors and take the median, favoring saturated colors. When I reduce the cat picture to 32 colors, the eyes get turned into a desaturated grey.

所以,我问你们,如果你知道任何算法或颜色的原则,可以让我发现,从图像中脱颖而出的颜色,而不模糊在一起。我希望有一个色彩,实际上是图像中的4-5色,而不是模糊的平均组合。

So I'm asking you guys if you know of any algorithm or color principle that will let me find colors that stand out from an image, without blurring them together. I want a color that is actually in the image, not the blurred mean of 4-5 colors combined.

在更普遍的意义,TinEye已经做得很完美,我想弄清楚他们是如何做到了。

In a more general sense, TinEye has done a perfect job, and I'd like to figure out how they've done it.

推荐答案

您说的显性的颜色是眼睛是蔚蓝色的刺耳的。

You say, that the 'dominant' color was 'that piercing azure of the eyes'.

您也说了,要作为结果的是饱和的蔚蓝是一个的5-6色彩在你提取的调色板。

You also say, that you want as a result 'that saturated azure being one of' the 5-6 colors in your extracted palette.

您终于想的色彩,实际上是图像中的4-5色组合,而不是模糊的意思。的。

要开始处理这个任务,我第一次尝试去确切的颜色定义的的眼睛是蔚蓝色的刺耳的。

To start tackling this task, I've first tried to get to the exact color definition of 'that piercing azure of the eyes'.

但在这里我卡已经:那撕心裂肺蔚蓝已经是蓝色的至少20种不同色调的组合!看到这里,一个图片是裁剪猫眼,1000%缩放级别:

But here I'm stuck already: that piercing azure is already a mix of at least 20 different shades of blue! See here, a picture that is a cropped cat eye, at 1000% zoom level:

那么,哪一个你到底想要什么?那么,如果你到底想象蓝色的最佳匹配是的 模糊平均 几种颜色的组合,并且不出现在原始图像甚至一度?!的

So which one exactly do you want? So what if the best match for the blue you imagine in the end is a 'blurred mean' of several colors combined, and which does not appear in the original image even once?!

这是我第一次拍吧...

Here is my first shot at it...

convert 2048.jpg -posterize 8 posterized-8.png

下面是猫的眼睛分色和放大1000%时:

Here is the cat's eye when posterized and zoomed at 1000%:

convert              \
   posterized-8.png  \
  -format %c         \
  -colorspace lab    \
  -colors 12         \
   histogram:info:-  | sort -n -r

  850708: (172,171,171) #ACABAB srgb(172,171,171)
  370610: (219,219,226) #DBDBE2 srgb(219,219,226)
  262870: (218,201,183) #DAC9B7 srgb(218,201,183)
  162588: (182,182,219) #B6B6DB srgb(182,182,219)
  161739: (182,219,219) #B6DBDB srgb(182,219,219)
  115671: ( 92, 87, 87) #5C5757 srgb(92,87,87)
  102337: (146,109,109) #926D6D srgb(146,109,109)
   86318: ( 67, 46, 46) #432E2E srgb(67,46,46)
   82882: ( 22, 20, 21) #161415 srgb(22,20,21)
   66221: (109,139,154) #6D8B9A srgb(109,139,154)
   58403: (146,146,109) #92926D srgb(146,146,109)
   38949: ( 97,109,146) #616D92 srgb(97,109,146)

3。使用12种最常见的色彩营造一个接线条带出调色板:

convert      \
   -size 100x100 \
    xc:"srgb(172,171,171)" \
    xc:"srgb(219,219,226)" \
    xc:"srgb(134,119,120)" \
    xc:"srgb(182,182,219)" \
    xc:"srgb(182,219,219)" \
    xc:"srgb(92,87,87)" \
    xc:"srgb(146,109,109)" \
    xc:"srgb(67,46,46)" \
    xc:"srgb(22,20,21)" \
    xc:"srgb(109,139,154)" \
    xc:"srgb(146,146,109)" \
    xc:"srgb(97,109,146)" \
   +append \
    palette.png

这是怎样的调色板看起来像(它忽略了颜色非常亮点的眼睛):

This is how the palette looks like (it misses the colors from the very bright spot in the eye):