Any transition serious enough to alter your definition of self will require not just small adjustments in your way of living and thinking but a full-on metamorphosis.
Color is the interpretation of the frequency (and therefore energy) of a photon. We perceive color with special color-sensitive cells in our eyes called cones, and intensity-sensitive cells called rods, which both coat the retina. When the lens focuses light through the iris, the light forms an image on the retina, and the cones and rods transmit this data through the optic nerve to the visual cortex for processing. There are three types of cones, which are (big shocker) sensitive to red, green, and blue light. These cones are actually sensitive to frequency bands, but I digress.
How do Computers Handle Color?
Not surprisingly, our computer monitors have red, green, and blue components within each pixel. By varying the intensity of each color channel in the pixels, we can reproduce any color we like by stimulating the cones and making them think they are seeing a particular frequency of light.
For most API's you'll be using, the values of each channel range from 0 to 255 (an eight bit integer for each channel), and these will all be stored side-by-side in a 32 bit long integer. Some API's use normalized color, or values ranging from 0.0 to 1.0, so check your documentation. 0 (or 0.0) indicates black, and 255 (or 1.0) indicates full saturation (the color is at maximum). You'll often see the term RGBA, meaning Red, Green, Blue, and Alpha (don't worry about the alpha channel for most cases - it is just for alpha-blending, or transparency.)
The Dreaded Mathematical Stuff
We can represent the three 8 bit color channels in what color theorists call the "color space" or "color cube." The first element in the color vector is red, the second is green, and the third is blue. So the color red at full saturation is <255, 0, 0> in color space.
Therefore, our color vectors live in the first octant, and occupy the region defined by a cube with corners at <0, 0, 0> and <255, 255, 255>. The diagonal from the origin to <255, 255, 255> contains pure gray scale values. Any color you can represent with a computer must live inside this cube.
Intensity and Desaturation
We can take any image and remove the color. This process is called desaturation. To desaturate the image, we find the intensity of each pixel. This is simply an average of the red, green, and blue component of the pixel. It approximates how bright the pixel appears. In mathematical terms,
I = (R + G + B) / 3
If we replace all the RGB values with the intensity (make R = G = B = I), we have effectively desaturated that pixel. Removing the color data from an image can be useful in some situations. For example, if given a color gradient, we can rank each line in the gradient by ignoring the color and simply looking at the intensity (!?).
Interpolation of Adjacent Pixels
We can get an "average color" by interpolating the color channels within two adjacent pixels. This is a good way to blur pixels, minimize the effects of noise, or to make stretched images look smoother. Let's say we have a red pixel next to a green pixel. Noise can be overcome by looking at adjacent pixels and interpolating (!?).
Mathematically,
<r_avg, g_avg, b_avg> = <r_i, g_i, b_i> / N
Where i ranges from 1 to N, and N is the total number of pixels being interpolated. If unfamiliar with vector algebra, go to the library and educate yourself.
This is basically what happens to the eye when distant objects are viewed. If the eye can't resolve objects that are too distant, they sort of merge together with the average color and intensity given off by both.
Hiding Data using Colors
I'm sure you have seen cases where bitmaps hide enciphered data. Well, suppose we subtract 1 from each red channel in each pixel. Think the image will look different? For three color bytes, there are 256^3 possible colors. So the difference is one part in 16,777,216. Human eyes are sensitive, but not that sensitive. We could take an image and add 1 to each red pixel for each binary 1 in our clear text or cipher from the original picture. It is essentially a one time pad, as long as you use a real photo and not something you made in MS Paint. The original image becomes the key. Simple. This is but one example - there are really countless schemes to use images to hide data in images.
Stay tuned for handling bitmaps using C++.
Cast your vote on this article 10 - Highest, 1 - Lowest
Comments: Published: 4 comments.
HackThisSite is the collective work of the HackThisSite staff, licensed under a CC BY-NC license.
We ask that you inform us upon sharing or distributing.