5

我想提取图像中最常用的颜色,或者至少是主色调你能推荐我如何开始这项任务吗?或指向我类似的代码?我一直在寻找它,但没有成功。

4

3 回答 3

4

使用八叉树颜色量化算法可以获得非常好的结果。其他量化算法可以在Wikipedia上找到。

于 2009-11-24T04:37:14.777 回答
3

我同意这些评论 - 编程解决方案肯定需要更多信息。但在那之前,假设您将获得图像中每个像素的 RGB 值,您应该考虑HSV 颜色空间,其中色调可以说是代表每个像素的“色调”。然后,您可以使用直方图来识别图像中最常用的色调。

于 2009-11-24T04:21:29.520 回答
2

Well, I assume you can access to each pixel RGB color. There are two ways you can so depending on how you want it.

First you may simply create some of all pixel's R, G and B. Like this.

A pseudo code.


int Red   = 0;
int Green = 0;
int Blue  = 0;
foreach (Pixels as aPixel) {
    Red   += aPixel.getRed();
    Green += aPixel.getGreen();
    Blue  += aPixel.getBlue();
}

Then see which is more.

This give you only the picture is more red, green or blue.

Another way will give you static of combined color too (like orange) by simply create histogram of each RGB combination.

A pseudo code.


Map ColorCounts = new();
foreach (Pixels as aPixel) {
    const aRGB   = aPixel.getRGB();
    var   aCount = ColorCounts.get(aRGB);
    aCount++;
    ColorCounts.put(aRGB, aCount);
}

Then see which one has more count. You may also reduce the color-resolution as a regular RGB coloring will give you up to 6.7 million colors.

This can be done easily by given the RGB to ranges of color. For example, let say, RGB is 8 step not 256.

A pseudo code.



function Reduce(Color) {
    return (Color/32)*32; // 32 is 256/8 as for 8 ranges.
}
function ReduceRGB(RGB) {
    return new RGB(Reduce(RGB.getRed()),Reduce(RGB.getGreen() Reduce(RGB.getBlue()));
}

Map ColorCounts = new();
foreach (Pixels as aPixel) {
    const aRGB   = ReduceRGB(aPixel.getRGB());
    var   aCount = ColorCounts.get(aRGB);
    aCount++;
    ColorCounts.put(aRGB, aCount);
}

Then you can see which range have the most count.

I hope these technique makes sense to you.

于 2009-11-24T04:26:14.613 回答