views:

48

answers:

3

Hi guys, I don't have much experience doing image analysis so I thought I'd ask more enlightened individuals :)

Basically what I want to do is analyse an image and work out what the most common colours are (these will be averages obviously).

Does anybody know of an effective way to do this? If at all possible I'd like to avoid using any third party libraries, but everything will be considered at least.

Like I said, I don't have much experience with image analysis so please be patient with me if I don't understand your answers properly!

I've tried Google but there doesn't seem to be anything resembling what I'm after. Maybe my Google-Fu just isn't good enough today.

I'd really appreciate any pointers you guys could give!

Thanks, Tom

+1  A: 

Consider a "color cube" with RGB instead of XYZ. Split the cube into subcubes, but make them all overlap. Ensure they are all the same size. An easy to remember/calculate cube-pattern would be one that goes from 0-127, 64-191, 128-255 in all directions, making for a total of 27 cubes. For each cube, find what colors in the image fall into them.

As you make the cubes smaller and smaller, the results will change less and less and begin to converge on the most popular color ranges. Once you have that convergence, take the average of the range to get the "actual color".

That's about as much detail as I can go into with my boss hovering around the cubefarm :-)

glowcoder
I think this seems like the best way to do it so far. I read about this method on another website (for a slightly different purpose) and I think part of the attraction is it just kind of sounds cool :PI'd still like to try a few different methods and see which gives the best results, but thanks anyway, I'll try yours first :)
TomFromThePool
+1  A: 

A rough idea of how you might be able to do this:
You could use java.awt.image.PixelGrabber to grab a 2D array of RGB ints from the image, pixel by pixel.

When you have this array populated, you can go through and sort however you want (sounds like it would be memory-intensive), and perform simple functions to order them, count them, etc.

Then you could look at java.awt.Color and, using the Color(int, int, int) constructor, create boxes with those colors (as visual placeholders) with the number of occurrences appearing below it.

To get the hex values for the color, you can use a String like so:

    String rgb = Integer.toHexString(color.getRGB());
    rgb = rgb.substring(2, rgb.length());

(substring is necessary, otherwise you'd get 8 characters)

Hopefully this gets you on the right track!

Resources: Color Class, Image Class

rownage
A: 

I know your trying to avoid third party libraries, but do take a look at OpenCV. They have some good stuff w.r.t image manipulation and analysis. Maybe that can work for you.

Sharath