我想提取图像中最常用的颜色,或者至少提取主要色调您能推荐我如何开始这项任务吗?或指向我类似的代码?我一直在寻找它,但没有成功。
使用Octree Color Quantization algorithm可以获得非常好的结果。其他量化算法可以在Wikipedia上找到。
我同意这些意见-编程解决方案肯定需要更多信息。但是直到那时,假设您将获得图像中每个像素的RGB值,则应考虑HSV colorspace,可以说色相代表每个像素的“色调”。然后,您可以使用histogram识别图像中最常用的色调。
嗯,我想您可以访问每种像素的RGB颜色。您可以根据自己的需要选择两种方法。
首先,您可以简单地创建所有像素的R,G和B。像这样。
伪代码。
int Red = 0;
int Green = 0;
int Blue = 0;
foreach (Pixels as aPixel) {
Red += aPixel.getRed();
Green += aPixel.getGreen();
Blue += aPixel.getBlue();
}
然后查看更多。
这只会给您更多红色,绿色或蓝色的图像。
另一种方法也可以通过简单地创建每个RGB组合的直方图来为您提供混合颜色的静态效果(如橙色)。>
伪代码。
Map ColorCounts = new(); foreach (Pixels as aPixel) { const aRGB = aPixel.getRGB(); var aCount = ColorCounts.get(aRGB); aCount++; ColorCounts.put(aRGB, aCount); }
然后查看哪个有更多的计数。您还可以降低颜色分辨率,因为常规的RGB色彩最多可以提供670万种颜色。
这可以通过将RGB赋予颜色范围来轻松完成。例如,假设RGB是8步而不是256。
伪代码。
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); }
然后您可以查看哪个范围计数最高。
我希望这些技术对您有意义。