Sunday, March 09, 2008

Refined RGB color grouping logic

As I mentioned earlier, I had to group colors. I wrote a simple logic where I put zeros in the last n number bits of each color pigment of each color pixel. This gave the required result, but gave distorted colors.
In the quest of minimizing the distorting, I arrived at a better calculation. The line of thought is:
  • if we want to group colors together, we will have to mask the LSB bits of each color
  • Masking can be either making those choosing last n bits as all zeros or all ones
  • choosing either one of the above would lead to distortion
  • Instead of fixing the bits towards 0s or 1s, I tried to find a uniform number that could be placed at the last n bit.
  • This involves scanning all the red pigment of all the pixels. Add the last n bit values from these pixels and find average. Trim this average number to n bit size and paste this n bit at the end of all red pigment for all the pixel colors. Do this for green and blue as well.

After trying this approach, I got a better colors that were grouped together.

No comments: