Extracting Dominant / Most Used Colors from an Image
G

3

5

I would like to extract the most used colors inside an image, or at least the primary tones Could you recommend me how can I start with this task? or point me to a similar code? I have being looking for it but no success.

Giguere answered 24/11, 2009 at 4:7 Comment(5)
What language or framework are you working with?Heterodyne
The answer will heavily depend on your environment.Strobilaceous
Well, I was thinking about processing just for a proof of concept and then translate it to python for batchingGiguere
If you like an answer, you might consider clicking on the uparrow to indicate that it was useful. If you think the answer was the solution to your problem, you should click on the checkmark to select it as the accepted answer.Hearts
thank you, I dindt know, I just register in this awesome community! but I cannot click in the up arrow because I have zero karma :(Giguere
H
4

You can get very good results using an Octree Color Quantization algorithm. Other quantization algorithms can be found on Wikipedia.

Hearts answered 24/11, 2009 at 4:37 Comment(1)
@dineshprasanna, no I can't. If Google can't help you then you might have to write your own using the information provided at the link.Hearts
P
3

I agree with the comments - a programming solution would definitely need more information. But till then, assuming you'll obtain the RGB values of each pixel in your image, you should consider the HSV colorspace where the Hue can be said to represent the "tone" of each pixel. You can then use a histogram to identify the most used tones in your image.

Panties answered 24/11, 2009 at 4:21 Comment(1)
N.B. by "HSV colorspace" you most likely mean to say "HSV-mode RGB model" -- HSV (and its fraternal twin HSL) are distortions of an RGB color model; pretty much anyone who refers to an RGB model (or, erroneously, an "RGB color space") is dealing with representations of values in the CIE-XYZ'39 color space. Not trying to specifically nitpick your answer, but there you go.Horodko
C
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.

Cas answered 24/11, 2009 at 4:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.