Monday, July 7, 2014

Reducing the Number of Colors (Part I)

In my last post I discussed a way to reduce the number of colors in grayscale image. So the natural step was to proceed to a color image. Let's start with a nice color image.

The color image is just a collection of a red, a green and a blue image.

The Ignorant Approach

The first thing I tried, just to see what would happen, was to try the algorithm I made for the grayscale image. That means repeating the process for the individual channels and later merging the result.
That works, but it doesn't give the result I am really looking for.

For some colors this approach works. The sky is a nice color blue, some bright yellow accents on the plane come out as I wanted, but some color like on the right wing seem wrong.
What the program found were 6,6 and 7 peaks for the color channels. That means that if a certain value of blue is very dominant that value will be picked. But the area that belongs to that color might not be purely blue.

Similar But Different

Here's an example of 6 colors with the same maximum blue value of 255, but with different red and green values.

Square with different RGB values, but the same blue value.

You can imagine that one of these colors is not found as a dominant. If a certain color is found it has to give rise to a peak in he histogram of all three colors.

The picture above is an example in two color dimensions, the x-axis representing green and the y-axis blue. The dots are both colors that occur in some image. But perhaps the one in the top is found in way more pixels then the one in the bottom. In the end the green value which is the same for both colors will be found probably. But the blue value of the lowest color might not be found. Every pixel with a color close to that bottom color will be assigned a green value that is correct, but the new blue value could be miles off.

3D RGB Space

For me the problem was beginning look a bit clearer, also a bit more difficult. When you look at all the colors that occur in an image there are thousands. Some are quite similar, like all those colors blue in the sky of our example image. Let's see what all these colors look like in the 3D RGB space.

3D RGB Space of the Spitfire image

What I have drawn here is all the pixels in the image placed in the RGB space. Easily understandable points are (0,0,0) which is black in the front and (255,255,255) as white in the back. Along the diagonal axis are all the gray colors. Off diagonal RGB values are the other colors, and you can see some groups, and a lot of empty space. What you can't see how many identical RGB points there are, and how many of are all alone.
That is why I made the same image but here I changed the size of the circles to show how many pixels have that color.

We are looking at it from a different angle, but it shows one thing; there are a lot of blue pixels.

That's about as far as I've come right now. What I intend to do next is to find the regions of this image where a lot colors are found close together (like that blue area in the top). So this is similar to finding a peak in 1D histogram, but than more like finding a 3D peak (a blob with the highest density).
I am still thinking of what the best approach is going to be for this. 

Stay tuned!

No comments:

Post a Comment