Changing the hue

It has been easy to find special color transformations for 2- and 3-color symmetries. For other color symmetries I use a rather general color transformation that changes the hue.

First, we separate the pixel color in a grey part and a pure color part. The grey part is given by the smallest of the three pixel color components:

grey=min(red,green,blue).

We subtract this value from the red, green and blue components. One of these values is then equal to zero. The larger of the other two values is the intensity of the color part:

intensity=max(red,green,blue)-grey.

Finally, we have to define a numerical value for the hue to characterize the color. The hue is cyclic. We can assign the value 0 to red, going to yellow for 1, green for 2, cyan for 3, blue for 4, magenta for 5 and then comes red again for 6. For intermediate colors we use an interpolation that comes directly from the color components. As an example, subtracting grey the pure red has color components

red-grey=intensity, green-grey=0, blue-grey=0

and the pure yellow is made of

red-grey=intensity, green-grey=intensity, blue-grey=0.

For intermediate colors like orange the hue is given by

hue=(green-grey)/intensity.

Similarly, we get the value for the hue of other colors. That’s how to calculate the values of grey, intensity and hue parameters from the red, green and blue channels and inversely.

To transform the color of a pixel we get first the grey, hue and intensity values from its red, green and blue channels. Then we change the hue. For an n-color symmetry we would add 6/n. Finally, we calculate the values for red, green and blue channels using the new value of the hue.

We can do other color manipulations too. Here, a minstrel bug with red and black stripes becomesĀ a rainbow bug:

 

This entry was posted in Kaleidoscopes, programming and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s