<< Chapter < Page Chapter >> Page >

The rgb model

Colors are represented by a triple of numbers, each giving the intensity of the primary colorsRed, Green, and Blue. Each number can be an unsigned integer, thus taking values between0 and 255, or be expressed as a floating point number between 0.0 and 1.0 . With even larger flexibility, the model, type, and range of colors can be set with the function colorMode() . The RGB model is additive.

Hsb model

Colors are represented by a triple of numbers, the first number giving the Hue, the second giving Saturation, and thethird giving the Brightness.

Often the model is called HSV, where V stands for Value.
The hue takes values in degrees between 0 (red) and 360 , being the various hues arranged along a circumference and being red positioned at 0 ˚ . Saturation and brightness vary between 0 and 100 . The saturation is the degree of purity of color. If a pure color is added with a white light its degree of puritydecreases until the color eventually sits on a gray scale when saturation is zero. In physical terms, the brightness isproportional to the signal power spectrum. Intuitively, the brightness is increased when the light intensityincreases. The three-dimensional HSB space is well represented by a cylinder, with the hue (nominal scale) arranged along thecircumference, the saturation (ratio scale) arranged along the radius, and the brightness (interval scale) arranged along thelongitudinal axis. Alternatively, such three-dimensional space can be collapsed into two dimensions, as in the color chooser of the image-processing program Gimp , displayed in [link] . Along the circumference, the three primary colors (red, green, and blue) are visible, 120 ˚ apart from each other, separated from the secondary colors (magenta, cyan, yellow). Each secondary color iscomplementary to the primary color in front of it in the circumference. For instance, if we take the green componentout of a white light, we obtain a magenta light. The triangle inscribed in the circumference has a vertex pointing to aselected hue. The opposite side contains the gray scale, thus representing colors with null saturation and variablebrightness. Going from the reference vertex to the opposite side we have a gradual decrease in saturation.

Gimp color chooser

Color chooser of the software Gimp

Alpha channel

It is a byte used to blend and interpolate between images, for example to render transparency. It can be obtained, from avariable of type color , with the method alpha() . The alpha channel can be manipulated with the method blend() of the class PImage .

Loading and visualizing an image with transparency

size(400,300);PImage b = loadImage("gondoliers.jpg"); PImage a = loadImage("gondoliers.jpg");float ramp = 0; for (int j = 0; j<b.height; j++) for (int i = 0; i<b.width; i++) { b.set(i, j, b.get(i,j) +color(0,0,0, 255 - (int)((1-ramp)*255)) ); ramp = ramp + 1/(float)(b.width * b.height);} a.blend(b, 0, 0, b.width, b.height,80, 10, 450, 250, BLEND); image(a, 0, 0, 400, 300);
Got questions? Get instant answers now!

In Processing, it is possible to assign a color to a variable of type color by means of the function color() , and the model can be previously set with colorMode() . The functions red() , green() , blue() , hue() , saturation() , and brightness() allow to move from one model to the other. colorMode(RGB); color c1 = color(102, 30,29);colorMode(HSB); color c2 = color(hue(c1), saturation(c1), brightness(c1));colorMode(RGB); color c3 = color(red(c2), green(c2), blue(c2));// the variables c1, c2, and c3 contain the coding of the same color

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Media processing in processing. OpenStax CNX. Nov 10, 2010 Download for free at http://cnx.org/content/col10268/1.14
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Media processing in processing' conversation and receive update notifications?

Ask