Shift hue of an RGB Color?

Basically there are two options: Convert RGB -> HSV, change hue, convert HSV -> RGB Change the hue directly with a linear transformation I'm not really sure about how to implement 2, but basically you'll have to create a transformation matrix and filter the image through this matrix. However, this will re-color the image instead of changing only the hue. If this is ok for you, then this could be an option but if not a conversion cannot be avoided.

Edit A little research shows this, which confirms my thoughts. To summarize: The conversion from RGB to HSV should be preferred, if an exact result is desired. Modifying the original RGB image by a linear transform also leads to a result but this rather tints the image.

The difference is explained as follows: The conversion from RGB to HSV is non-linear, whereas the transform is linear.

Made an edit. I'll do this directly next time, without reminder ;) – macs Dec 14 at 19:23 All right, thanks! – Josh Caswell Dec 14 at 19:36.

The RGB color space describes a cube. It is possible to rotate this cube around the diagonal axis from (0,0,0) to (255,255,255) to effect a change of hue. Note that some of the results will lie outside of the 0 to 255 range and will need to be clipped.

I finally got a chance to code this algorithm. It's in Python but it should be easy to translate to the language of your choice. The formula for 3D rotation came from en.wikipedia.org/wiki/Rotation_matrix#Ro... You pass the cosine and sine of the hue rotation angle into the function; this saves having to recalculate them every time.

From math import sqrt f1_3 = 1.0 / 3.0 sqrt_1_3 = sqrt(f1_3) def clamp(v): if v 255: return 255 return int(v + 0.5) def rotate_hue(r, g, b, cosA, sinA): c = f1_3 * cosA c2 = c * 2.0 s = sqrt_1_3 * sinA rx = r*(f1_3 + c2) + g*(f1_3 - c - s) + b*(f1_3 - c + s) gx = r*(f1_3 - c + s) + g*(f1_3 + c2) + b*(f1_3 - c - s) bx = r*(f1_3 - c - s) + g*(f1_3 - c + s) + b*(f1_3 + c2) return (clamp(rx), clamp(gx), clamp(bx)) Here are some results from the above: You can find a different implementation of the same idea at graficaobscura.com/matrix/index.html.

It seems converting to HSV makes the most sense. Sass provides some amazing color helpers. It's in ruby, but it might provide useful.

sass-lang.com/docs/yardoc/Sass/Script/Fu....

Essentially, the steps you want are RBG->HSV->Update hue->RGB Since these are all linear matrix transforms (i.e. They are associative), you can perform it in a single step without any nasty conversion or loss of precision. You just multiple the transform matrices with each other, and use that to transform your colors.

There's a quick step by step here beesbuzz.biz/code/hsv_color_transforms.php Here's the C++ code (With the saturation and value transforms removed): Color TransformH( const Color &in, // color to transform float H ) { float U = cos(H*M_PI/180); float W = sin(H*M_PI/180); Color ret; ret. R = (.701*U+.168*W)*in. R + (-.587*U+.330*W)*in.

G + (-.114*U-.497*W)*in. B; ret. G = (-.299*U-.328*W)*in.

R + (.413*U+.035*W)*in. G + (-.114*U+.292*W)*in. B; ret.

B = (-.3*U+1.25*W)*in. R + (-.588*U-1.05*W)*in. G + (.886*U-.203*W)*in.

B; return ret; }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions