views:

39

answers:

2

Any suggestions on how I might go about plotting the RGB color space as a 2-D matrix? I need a theoretical description of what's going on; a code sample or pseudocode would be helpful but is not required. Thanks!

+1  A: 

If you don't want to lose any information, you will need to use three dimension. If you can lose some dimensional information, then it's easy. Just do this:

// or HSV
int [256*256][256] colorMatrix;
for (int r = 0; r < 256; r++) {
    for (int r = 0; r < 256; r++) {
        for (int r = 0; r < 256; r++) {
            colorMatrix[256*r+g][b] = color(r, g, b);
        }
    }
}
Lie Ryan
So it IS too much information to pack into two dimensions. Any reason we chose blue to represent 'more fully'? Does the human visual system process blue any differently? Just curious, +1 and accepted
Joe
@Joe: no reason whatsoever. Multi-dimensional arrays is actually just syntax sugar for a 1-dimensional array accessed like such: `arr[r*(256*256)+g*256+b]` or `arr[(r*256+g)*256+b]`
Lie Ryan
+1  A: 

There isn't really a good answer for 2D, because you really need 3 dimensions. Of course, you can project a 3D space onto 2D, but to retain a meaningful amount of information you nearly need to provide the normal 3D manipulation, so you can see the projection viewed from various different angles and such.

Jerry Coffin
Probably a stupid question, but how could you see 'into' the 3-d projection? Wouldn't it be filled with solid (or muddled) colors?
Joe
@Joe: MS Paint's color chooser is one example. You see a 2D matrix at a time (Hue and Saturation, in MS Paint), and have a scroller that selects the third dimension (the Brightness/Value, in the case of MS Paint). To see all colors at the same time though, would require a screen capable of displaying 16 777 216 pixels (for reference: 1024*768 screen displays 786 432 pixels at a time). Or you would have a semi transparent cube, which results in, as you guessed, a muddled colors.
Lie Ryan
@Joe: you don't attempt to make the 3D projection transparent to any degree. Rather, you display a 2D "slice" of the volume.
Jerry Coffin
Yes, I get that; what would be a good strategy for taking slices of a 3-d RGB space? I'm used to the three sliders for HSV -- I guess I'm trying to understand how these slices are generated; I suppose they somehow 'rotate' the plane through the cube? OK. That actually totally makes sense -- RGB sliders would correspond to translations of the slice. But how would we make HSV sliders work, mathematically speaking? (If you're still around! Thanks for all your help.)
Joe
HSV and HSL both define basically cone-shaped volumes. The most common display is circles along the axis of the cone. This sort of all right for selecting individual colors, but not very good for visualizing the color space as a whole. One page worth looking at: http://www.gamutvision.com/docs/gamutvision_equations.html
Jerry Coffin
Excellent. Thank you. I think I have a good understanding of saturation and value, but I'm still struggling to wrap my mind around the idea of writing a single-parameter function for hue which 'smoothly' walks the RGB color space. Any advice? (I'm basically looking to programmatically create one of the last two color maps shown on the page you linked, "V, L, and H illustrated for S = 1 (maximum saturation)".)
Joe
Ah, it looks like a strategy is described in efg's HSV Lab Report. We just take a walk around the hexcone -- neat! Thanks for pointing me in the right direction.
Joe