What Wavelength Goes With a Color? Contact Us What Wavelength Goes With a Color? Our eyes are sensitive to light which lies in a very small region of the electromagnetic spectrum labeled "visible light". This "visible light" corresponds to a wavelength range of 400 - 700 nanometers (nm) and a color range of violet through red. The human eye is not capable of "seeing" radiation with wavelengths outside the visible spectrum. The visible colors from shortest to longest wavelength are: violet, blue, green, yellow, orange, and red. Ultraviolet radiation has a shorter wavelength than the visible violet light. Infrared radiation has a longer wavelength than visible red light. The white light is a mixture of the colors of the visible spectrum. Black is a total absence of light. Earth's most important energy source is the Sun. Sunlight consists of the entire electromagnetic spectrum. Learn more: Violet Light The visible violet light has a wavelength of about 400 nm. Within the visible wavelength spectrum, violet and blue wavelengths are scattered more efficiently than other wavelengths. The sky looks blue, not violet, because our eyes are more sensitive to blue light (the sun also emits more energy as blue light than as violet).

The visible indigo light has a wavelength of about 445 nm. Blue Light The visible blue light has a wavelength of about 475 nm. Because the blue wavelengths are shorter in the visible spectrum, they are scattered more efficiently by the molecules in the atmosphere. This causes the sky to appear blue during the main part of the day, when blue light is scattered into your eye no matter which direction you look. Green Light The visible green light has a wavelength of about 510 nm. Grass, for example, appears green because all of the colors in the visible part of the spectrum are absorbed into the leaves of the grass except green. Green is reflected, therefore grass appears green. The visible orange light has a wavelength of about 590 nm. Low-pressure sodium lamps, like those used in some parking lots, emit a orange-ish (wavelength 589 nm) light. Red Light The visible red light has a wavelength of about 650 nm. At sunrise and sunset, the light you see has traveled a longer distance through the atmosphere. A large amount of blue and violet light has been removed as a result of scattering and the longwave colors, such as red and orange, are more readily seen.

There are many wavelengths in the electromagnetic spectrum the human eye cannot detect. Energy with wavelengths too short for humans to see Energy with wavelengths too short to see is "more violet than violet". Light with such short wavelengths is called "Ultraviolet" light. The term "ultra-" means higher than. How do we know this light exists? One way is that this kind of light causes sunburns. Our skin is sensitive to this kind of light. If we stay out in this light without sunblock protection, our skin absorbs this energy. After the energy is absorbed, it can make our skin change color ("tan") or it can break down the cells and cause other damage. Energy with wavelengths too long for humans to see Energy whose wavelength is too long to see is "redder than red". Light with such long wavelengths is called "Infrared" light. The term "Infra-" means "lower than". How do we know this kind of light exists? One way is that we can feel energy with these wavelengths such as when we sit in front of a campfire or when we get close to a stove burner.

Scientists like Samuel Pierpont Langley passed light through a prism and discovered that the infrared light the scientists could not see beyond red could make other things hot. Very long wavelengths of infrared light radiate heat to outer space. This radiation is important to the Earth's energy budget. If this energy did not escape to space, the solar energy that the Earth absorbs would continue to heat the Earth. Molecular Expressions Microscopy Primer: Physics of Light and Color - Introduction to the Primary Colors Movie Gallery Introduction to the Primary Colors Light from the sun is composed of an almost continuous spectrum of electromagnetic radiation, with most of the energy being concentrated in wavelengths that lie between 220 and 3,200 nanometers in length. As they pass through the Earth's atmosphere, a majority of the light waves above 2,000 nanometers (infrared wavelengths) are absorbed by carbon dioxide, water vapor, and ozone so that most never reach the ground. The shorter ultraviolet waves are also absorbed by the ozone layer. This filtering effect of the atmosphere limits the spectrum of light waves reaching the ground to those having wavelengths between 320 and 2,000 nanometers.

The human eye is sensitive to a narrow band of electromagnetic radiation that lies in the wavelength range between 400 and 700 nanometers, commonly known as the visible light spectrum, which is the only source of color. When combined, all of the wavelengths present in visible light, about a third of the total spectral distribution that successfully passes through the Earth's atmosphere, form colorless white light that can be refracted and dispersed into its component colors by means of a prism. The colors red, green, and blue are classically considered the primary colors because they are fundamental to human vision. The eye contains cone cell photoreceptors (see Figure 1) embedded in the small central fovea of the retina that are tuned to respond to wavelengths distributed within these three regions (red, green, and blue) with specialized pigment proteins. All the colors of the visible light spectrum, ranging from violet to red, can be produced by adding or subtracting various combinations of the three primary colors. Light is perceived as white by humans when all three cone cell types are simultaneously stimulated by equal amounts of red, green, and blue light. Because the addition of these three colors yields white light, the colors red, green, and blue are termed the primary additive colors.

Interactive Java Tutorial Primary Additive Colors Explore how the three primary additive colors mix with each other in pairs to form complementary colors, or how all three can be added together to form the color white. When only one or two types of cone cells are stimulated, the range of perceived colors is limited. For example, if a narrow band of green light (540 to 550 nanometers) is used to stimulate all of the cone cells, only the ones containing green photoreceptors will respond to produce a sensation of seeing the color green. Human visual perception of non-primary additive colors, such as yellow, can arise in one of two ways. If the red and green cone cells are simultaneously stimulated with monochromatic yellow light having a wavelength of 580 nanometers, the cone cell receptors each respond almost equally because their absorption spectral overlap is approximately the same in this region of the visible light spectrum. The same color sensation can be achieved by stimulating the red and green cone cells individually with a mixture of distinct red and green wavelengths selected from regions of the receptor absorption spectra that do not have significant overlap.

The result, in both cases, is simultaneous stimulation of red and green cone cells to produce a sensation of yellow color, even though the end is achieved by two different mechanisms. The ability to perceive other colors requires the stimulation of one, two, or all three types of cone cells to a varying degree with the appropriate wavelength palette. If equal portions of green and blue light are added together, the resulting color is termed cyan. Likewise, equal portions of green and red light produce the color yellow, and equal portions of red and blue light yield the color magenta. The colors cyan, magenta, and yellow are commonly termed the complementary colors because each complements one of the primary colors in a white light mixture. Yellow (red plus green) is the complement of blue because when the two colors are added together white light is produced. Likewise, cyan (green plus blue) is the complement of red, and magenta (red plus blue) is the complement of green light. The complementary colors (cyan, yellow, and magenta) are also commonly referred to as the primary subtractive colors because each can be formed by subtracting one of the primary additives (red, green, and blue) from white light.

For example, yellow light is observed when all blue light is removed from white light, magenta forms when green is removed, and cyan is produced when red is removed. The color observed by subtracting a primary color from white light results because the brain adds together the colors that are left to produce the respective complementary or subtractive color. Figure 2 illustrates overlapped color circles of both the additive and subtractive primary colors. The areas of overlap indicate the new colors that are produced by addition and subtraction of various combinations using these six primary colors, and also demonstrate how the additive and subtractive primaries complement each other. When any two of the primary subtractive colors are added, they produce a primary additive color. As an example, adding magenta and cyan together produces the color blue, while adding yellow and magenta together produces red. In a similar manner, adding yellow and cyan produces green (see Figure 2). When all three primary subtractive colors are added, the three primary additive colors are removed from white light leaving black (the absence of any color). White cannot be produced by any combination of the primary subtractive colors, which is the main reason that no mixture of colored paints or inks can be used to print white.

Interactive Java Tutorial Primary Subtractive Colors Explore how the three primary subtractive colors mix with each other in pairs to form complementary colors, or how all three can be added together to form black. A good example of color addition and subtraction are the variations observed in sunlight color as the sun rises, passes overhead, and then sets. The color of sunlight changes as it passes through the Earth's atmosphere because collision of photons with the varying densities of air molecules removes some of the colors. When the sun is high in the sky in the late morning and early afternoon, the light appears to be yellow. As the sun approaches the horizon, the light must travel through a larger portion of the atmosphere and begins to turn orange and then red. This occurs because the air absorbs an increasing amount of blue light from the sun, leaving only the longer wavelengths in the red region of the visible light spectrum. The series of photographs presented in Figure 3 contain images of a playing card (the 3 of hearts), a green bell pepper, and a cluster of bluish-purple grapes superimposed on a black background. In the photograph on the left (Figure 3(a)), the three objects are illuminated with white light and appear as we expect them to appear under natural lighting.

In the second photograph (Figure 3(b)), the objects are illuminated with red light. Note that the playing card is reflecting all of the red light that strikes it, while only the grape stem and white highlights on the grapes and pepper reflect red light. The majority of red light impacting on the grapes and pepper is being absorbed. The third photograph of the series (Figure 3(c)) presents the objects under illumination with green light. The symbols on the playing card are now black and the body of the card is reflecting green light. The grapes are reflecting some green light, while the pepper appears normal (but with green highlights). The fourth photograph (Figure 3(d)) illustrates the objects under blue illumination. The grape cluster appears normal with blue highlights, but the stem has turned black and is now invisible. The playing card is reflecting blue light with black symbols and the pepper is reflecting blue light only on the highlights. This series of images demonstrates how an object that looks red (for example, in white light) absorbs blue and green wavelengths, but reflects wavelengths in the red region of the spectrum. Therefore the object is seen as red.

Interactive Java Tutorial Color Filters Experiment with filters to drag and drop red, green, and blue virtual color filters over objects illuminated both with white light and also previously filtered with one of the primary additive colors. The human eye is sensitive to very slight differences in color and is probably capable of distinguishing between 8-12 million individual shades of color. Most colors contain some proportion of all wavelengths in the visible spectrum. What really varies from color to color is the distribution of wavelengths in a given color. The predominant wavelength palette determines the basic hue of the color which can be, for example, purple, teal, beige, pink or orange. The ratio of the dominant wavelengths to other wavelengths determines the color saturation of the sample and whether it appears pale or deeply saturated. The intensity of the color and reflectivity of the object being imaged determine the brightness of the color (for example, dark or light blue). This is nicely illustrated below in the Munsell Color Tree, where each color is represented by a distinct position on the tree (see Figure 4). Hue color value is represented by placement on the circumference, saturation by the horizontal distance of the color from the central axis, and brightness by the vertical position on the trunk.

Much of this discussion has centered on the properties of visible light with respect to the addition and subtraction of transmitted visible light that can be visualized on the screen of a computer or television. Most of what is actually observed, however, is light that is reflected from objects around us, such as other individuals, buildings, automobiles, landscapes, etc. These objects do not produce light themselves, but emit color by a process known as color subtraction where certain wavelengths of light are subtracted (absorbed) and others are reflected (as illustrated in Figure 3). For example, a green leaf appears this color under natural sunlight because it is reflecting green wavelengths and absorbing all of the other colors. The hue, brightness, and color saturation of the reflected green light is determined by the exact spectrum of wavelengths that are reflected. Pigments and dyes are responsible for most of the color we see in the real world. Eyes, skin, and hair contain natural protein pigments that reflect the colors visualized in the people around us (in addition to any assistance by colors used in facial makeup and hair dyes). Books, magazines, signs, and billboards are printed with colored inks that create colors through the process of color subtraction.

In a similar manner, automobiles, airplanes, houses, and other buildings are coated with paints containing a variety of pigments. The concept of color subtraction, as discussed above, is responsible for most of the color produced by the objects just described. For many years, artists and printers have searched for substances containing dyes and pigments that are particularly good at subtracting specific colors. All color photographs, and other images that are painted or printed, are produced using just four colored inks or dyes--magenta, cyan, yellow (the subtractive primaries) and black (see Figure 5). Mixing inks or dyes having these colors in varying proportions can produce the colors necessary to reproduce just about any image or color. The three subtractive primaries could (in theory) be used alone, however the limitations of most dyes and pigments makes it necessary to add black to achieve true color tones. When an image is being prepared for printing in a book or magazine, it is first separated into the component subtractive primaries, either photographically or with a computer as illustrated above in Figure 5. Each separated component is made into a film that is used to prepare a printing plate for that color.

The final image is created by sequentially printing each color plate, one on top of another, using the appropriate ink to form a composite that recreates the appearance of the original. Paint is also produced in a somewhat similar manner. Base pigments containing the subtractive primaries are mixed together to form the various colors used in final paint preparations. This discussion has covered the various aspects of the primary additive and subtractive colors. In using the microscope to view and capture color images, the concepts of additive and subtractive primary colors are very important. Microscope light sources are usually tungsten-halogen bulbs that can emit a bright light with a color temperature centered around 3200 K, or arc lamps for fluorescence microscopy that produce a color temperature in the 5500 K range. To the observer, these appear as white light that can be absorbed, refracted, reflected, polarized, and/or transmitted by a specimen on the microscope stage. The rules of primary colors apply to how the specimen interacts with microscope light and determines what colors are displayed as the sample is visualized in the eyepieces.

These rules also apply to the film in a traditional camera system or a digital imaging device attached to the microscope, both of which depend upon the interrelationships between primary colors to capture images. Contributing Authors Kenneth R. Spring - Scientific Consultant, Lusby, Maryland, 20657. Michael W. Davidson - National High Magnetic Field Laboratory, 1800 East Paul Dirac Dr., The Florida State University, Tallahassee, Florida, 32310. Molecular Expressions: Science, Optics, and You: Light and Color - Primary Colors Home Primary Colors The human eye is sensitive to a narrow band of electromagnetic radiation that lies in the wavelength range between 400 and 700 nanometers, commonly known as the visible light spectrum. This small span of electromagnetic radiation is the sole source of color. All of the wavelengths present in visible light form colorless white light when they are combined, but can be refracted and dispersed into their individual colors by means of a prism. The colors red, green, and blue are classically considered the primary colors because they are fundamental to human vision. All other colors of the visible light spectrum can be produced by properly adding different combinations of these three colors.

Moreover, adding equal amounts of red, green, and blue light produces white light and, therefore, these colors are also often described as the primary additive colors. Interactive Java Tutorial Explore how the primary additive colors interact with one another to form new colors. As illustrated by means of the overlapping color circles in Figure 1, if equal portions of green and blue light are added together, the resultant color is cyan. Similarly, equal portions of green and red light produce the color yellow, and equal portions of red and blue light yield the color magenta. The colors cyan, magenta, and yellow are commonly termed the complementary colors because each complements one of the primary colors, meaning that the two colors can combine to create white light. For instance, yellow (red plus green) is the complement of blue because when the two colors are added together white light is produced. In the same way cyan (green plus blue) is the complement of red, and magenta (red plus blue) is the complement of green light. Interactive Java Tutorial Primary Subtractive Colors Examine how the primary subtractive colors combine to form the primary additives, as well as black, the absence of all color.

The complementary colors (cyan, yellow, and magenta) are sometimes alternatively referred to as the subtractive primaries. This is because each one can be formed by subtracting one of the primary additives (red, green, and blue) from white light. For example, yellow light is seen when all blue light is removed from white light, magenta when green is removed, and cyan when red is removed. Consequently, when all three of the subtractive primary colors are combined, all of the additive primary colors are subtracted from white light, which results in black, the absence of all color. Thus far this discussion has centered on the properties of visible light with respect to the addition and subtraction of transmitted visible light, which is often visualized on the screen of a computer or television. Most of what is actually seen in the real world, however, is light that is reflected from surrounding objects, such as people, buildings, automobiles, and landscapes. These objects do not produce light themselves, but emit color through a process known as color subtraction in which certain wavelengths of light are subtracted, or absorbed, and others are reflected. For instance, a cherry appears red in natural sunlight because it is reflecting red wavelengths and absorbing all other colors.

The series of photographs presented below in Figure 2 helps further illustrate this concept. In the first photograph on the left, a playing card, a green bell pepper, and a cluster of purple grapes are illuminated with white light and appear as one would expect to see them under natural lighting. In the second photograph, however, the objects are illuminated with red light. Note that the playing card reflects all of the light that strikes it, while only the grape stem and highlights on the grapes and pepper reflect the red light. The majority of the red light is being absorbed by the grapes and pepper. The third photograph shows the objects under green illumination. The different radiation wavelength causes the symbols on the playing card to appear black and the body of the card to reflect green light. The grapes reflect some green light, while the pepper appears normal, but with green highlights. The fourth photograph illustrates the objects under blue illumination. In this situation, the grape cluster appears normal with blue highlights, but the stem is invisible because it blends into the black background. The body of the playing card reflects blue light and the symbols appear black, while the pepper only reflects blue light as highlights.

Interactive Java Tutorial Color Filters Investigate how color filters operate to alter the apparent color of objects visualized under white light and monochromatic illumination. The human eye can perceive very slight differences in color and is believed to be capable of distinguishing between 8 to 12 million individual shades. Yet, most colors contain some proportion of all wavelengths in the visible spectrum. What really varies from color to color is the distribution of those wavelengths. The predominant wavelengths of a color determine its basic hue, which can be, for example, purple or orange. It is the ratio of the dominant wavelengths to other wavelengths, however, that determines the color saturation of the sample and whether it appears pale or deeply saturated. The intensity of the color and reflectivity of the object being imaged, on the other hand, determine the brightness of the color, which controls, for instance, whether something appears dark or light blue. Over the years, various classification systems have been devised to systematically express color in terms of these concepts. One of the most widely accepted has been the Munsell Color Tree, which appears below in Figure 3. As illustrated, each color in this system is represented by a distinct position on the tree.

Hue color value is represented by placement on the circumference, saturation by the horizontal distance of the color from the central axis, and brightness by the vertical position on the trunk. When learning about color, it is also important to consider pigments and dyes, which are responsible for much of the color that appears on Earth. For instance, the natural protein pigments that are contained in eyes, skin, and hair reflect and absorb light in such a way that creates a beautiful diversity of appearances in the human race. In order to achieve a similar diversity of color in inanimate objects, such as automobiles, airplanes, and houses, they are frequently coated with pigment-containing paints and portray different shades through the process of color subtraction. Printed items, such as books, magazines, signs and billboards, create colors in the same fundamental way, but through the help of dyes or inks, rather than pigments. All color photographs, and other images that are printed or painted, are produced using just four colored inks or dyes--magenta, cyan, yellow (the subtractive primaries) and black. Mixing inks or dyes of these colors in differing proportions can produce the colors necessary to reproduce almost any image or color.

The three subtractive primaries could, in theory, be used alone. However, the limitations of most dyes and inks make it necessary to add black to achieve true color tones. When an image is being prepared for printing in a book or magazine, it is first separated into the component subtractive primaries, either photographically or with a computer as illustrated above in Figure 4. Each separated component is then made into a film that is used to prepare a printing plate for that color. The final image is created by sequentially printing each color plate, one on top of another, using the appropriate ink to form a composite that recreates the appearance of the original. Paint is produced in a somewhat similar manner. Again, only the subtractive primaries and black are required. Base pigments containing these colors are mixed together to form the various colors used in final paint preparations. Interactive Java Tutorial Color Separation Discover how the subtractive primaries are separated from an image and are made into color plates that can be used to produce realistically colored prints. A clear understanding of the color concepts previously discussed is extremely important when using a microscope to view and capture color images.

Microscope light sources are usually tungsten-halogen bulbs that can emit a bright light with a color temperature around 3200 Kelvin. To the observer, this appears as white light that can be absorbed, refracted, reflected, polarized, and/or transmitted by a specimen on the microscope stage. The rules of primary colors apply to how the specimen interacts with microscope light and what colors are displayed as the sample is visualized in the eyepieces. The same rules also apply to the film used to capture photomicrographs. Contributing Authors Mortimer Abramowitz - Olympus America, Inc., Two Corporate Center Drive., Melville, New York, 11747. Shannon H. Neaves and Michael W. Davidson - National High Magnetic Field Laboratory, 1800 East Paul Dirac Dr., The Florida State University, Tallahassee, Florida, 32310. Visible Spectrum | Chemistry@TutorVista.com Top Visible Spectrum Visible spectrum, which is also known as visible light or simply light, is a portion of the electromagnetic spectrum that the human eye can perceive. The range visible to humans is only a small part of the spectrum of electromagnetic waves.

Merely wave lengths in a very small interval from 380 to 780nm are normally perceived by humans as visible light. Wavelength at the left end of the range between 380 and 440nm are perceived as violet. With increasing wavelength the color impression changes to blue, green, yellow, orange and finally red. Red is perceived at wavelengths above 600nm. The associated wavelengths are subject to individual variations in color perception. The electromagnetic spectrum covers an enormous range of wavelengths. Visible light constitutes only a small portion of the total electromagnetic spectrum. It is only this part which our eyes can see. Visible light is produced from stars, arc lamps and glass enclosed tungsten filaments. It lies in a narrow range of wavelength between 300nm to 760nm. It lies between the Ultra-violet radiation and Infra red radiation of the electromagnetic radiation [EMR]. A white light is composed of seven different colors. Violet color corresponds to a radiation of maximum frequency (7.6 x 10^14 Hz.) and minimum wavelength (380nm). Indigo color corresponds to wavelength of 430-460nm.

Blue color corresponds to the wavelength of 460- 500nm. Green color corresponds to the wavelength of 500-560nm. Yellow color corresponds to the wavelength of 560-595nm. Orange color corresponds to the wavelength of 595 -620nm. Red color corresponds to the radiation of minimum frequency (4 x 10^14Hz) and maximum wavelength (760nm). Complementary color Blue Gray, white and black are not considered as a visible spectrum color. Black is not a color, but itâ€™s the lack of color. Deficiency of light develops blackness. On the contrary, white is a mix of all the possible colors of the visible spectrum. Out of seven colors Red, green and blue are known as "primary" colors as their combination produced white color. Two primary color mixed together to form secondary color. Hence by mixing of primary colors; red, green and blue, produced secondary color; Cyan, Magenta and Yellow. Mixing of secondary colors produced tertiary Colors. When white light passes through a prism, it gets dispersed into the colors of the optical spectrum.

This white light must be monochromatic light, i.e., visible light of a single wavelength. The visible spectrum appears continuous not in the form of bands. Hence there are no definite boundaries between the colors. The approximate ranges of wavelength and frequency can be used to specify the difference. Light and Color Light and Color This tutorial is about color, which is no doubt a very important aspect of computer graphics. First is explained how light is built up and why we actually see different colors. Then a some color models are explained: first the RGB color model used by computers, and examples showing how to do color arithmetics in RGB, and then the more intuitive HSL/HSV models are explained. Then code is given that allows you to convert between color models, for example to allow a user to pick a color using the HSV color model and then convert it to RGB so the computer can use it, or to create rainbow gradients, or to change the color of images. Light Before starting about color models, it's important to know how the human eye and brain turn light into color. Light itself is an electromagnetic wave. Electromagnetic waves are similar to sound waves in that they contain different frequencies, but are electromagnetic and can propagate in vacuum.

EM waves are thus a signal that's made out of one or more frequencies, for example the EM waves used by a microwave oven are very high frequency, while radio waves are very low frequency. The eye is only sensitive to a very narrow band of frequencies, namely the frequencies between 429 THz and 750 THz (1 THz = 1 TeraHertz = 10^12 Hz). All other EM waves can't be seen. Monochromatic light is light made up of one single pure frequency (this is certainly not the general case, most light you see is multichromatic). Monochromatic light looks to the eye as a pure color, and can never be white or magenta. Since it contains only one frequency, the wave of monochromatic light can be represented as a sine: The height of the sine is the amplitude or how bright the light is. The width of one period (called lambda) is the wavelength of the light, and is inversely related to the frequency: since the light travels at 300000000 m/s, its wavelength is 300000000/f where f is the frequency.

So the visible spectrum of light has wavelengths from around 400 to 700 nm.(1 nm = 10^-9 meter). This visible spectrum shows all the possible colors that can be made out of monochromatic light. Some light sources, such as lasers and Natrium lights, send out monochromatic light, but in general, light is multichromatic. For example, the sun sends out white light, which is light that contains ALL frequencies! That means the sum of red, yellow, green, blue and violet light looks like white! Physically speaking, it's not white at all, it's the sum of a lot of sine curves, but the human brain makes it look white. Color is thus something psychologically, and not something physical. Lightwaves are a sum of many different frequencies, or the sum of many sine curves. Each of these sine curves has its own frequency, and can have its own amplitude. A spectrum shows for each frequency the amplitude. For more information about spectra in general, see the beginnings of the chapter about Fourier Transforms. Here's an example of such a spectrum: It is the spectrum of a yellow LED I found.

The top of the spectrum is the Dominant Frequency, and that is the color our eyes will usually see if light with this spectrum shines on it. If this yellow LED would have been monochromatic, the spectrum would have looked like this instead: And to the eyes, the color would look the same. So here an interesting fact shows up: light with different spectra, can still look the same to the eye! If the human eyes would be able to distinguish every single spectrum as a different color, we would've been able to see gazillions of different colors, but the human eye works differently and turns a whole spectrum into only 3 signals: the amount of detected red, green and blue, and combinations of those make the colors we can see. The spectrum of white light is as follows (the height of the curve doesn't really matter): All frequencies are equally much in the light, only then it looks purely white to the brain. In all other cases, a certain frequency will be dominant and then that frequency will be the color the brain sees. The spectrum of black light looks like this: Indeed, there's no light at all, the amplitude of every frequency is zero. Black is the color the brain gives to the absence of light.

The spectrum of magenta, a color that can't be made with monochromatic light, could look like this: Both blue and red have a high amplitude, and the mix of blue and red frequencies looks like magenta or purple to the brain. The Eye and Color Perception This section isn't about how the physical structure of the eye and the lens work, but about how the eye and the brain distinguish different colors. So light falls on the retina, and on the retina are 2 types of cells with photosensitive chemicals, photoreceptors: rods and cones. The rods only detect whether or not light is present, and are important at night. So rods are sensitive to the whole spectrum at once and can't tell what frequency the light has, and thus can't provide any color information. To detect color, you'd need photoreceptors that are sensitive to only a certain frequency. That's exactly what the cones do: There are 3 types of cones, those that are sensitive to red, those sensitive to green, and those sensitive to blue. Such a rod isn't sensitive to a single frequency, they overlap a bit, it's just sensitive mostly to a certain frequency. For example, yellow has a frequency between red and green.

This yellow frequency will excite both the red and green cones a bit, and the human brain converts the signal "both red and green cones are excited" to "yellow". Even the blue cones are still a bit excited by yellow light, but neglectable. If light falls on the eye that has two frequencies: red and green, it'll also excite both the red and green cones, so this light will show up as yellow as well, even though it doesn't contain any yellow frequency at all. If blue light falls on the retina, the blue cones are excited very strongly, while the green and red ones will give only a neglectable signal. And the brain turns the signal "mainly the blue cone is excited" to "blue". White light contains all frequencies, so if white light falls on the retina, all 3 types of cones are excited, and the brain turns the signal "green, red and blue cones all excited" into "white".

The above explains how the brain creates different "hues" of colors out of the incoming signal, but it also gives a certain brightness to the light, based on how strong the incoming signal is: if it's very strong, the brain indicates it as a very bright red, white, ..., but if it's very weak, it'll be almost black. And then there's also the "saturation" of the color, this is based on the relative difference in strength each color type gives: if the red signal is very strong, but blue and green are also pretty strong, the color will have a low saturation, it's red-grayish or red-whitish. If however the red signal would be very strong, and the blue and green signal very weak, a very red color shows up. Since different spectra can look exactly the same for us, and some animals have different types of color receptors, it's possible that two colors that look the same to us, look like two different colors for some animal. The above process happens on every location of the retina separately, so that a complex 2-dimensional image is formed where each location on the image can have its own color.

Thanks to the 3 types of cones, there are 8 (2^3) main colors one can distinguish: No cones excited: Black Red cones excited, but not the Blue and Green ones: Red Green cones excited, but not the Blue and Red ones: Green Blue cones excited, but not the Red and Green ones: Blue Red and Green cones excited, but no the Blue ones: Yellow Blue and Green cones excited, but no the Red ones: Cyan Red and Blue cones excited, but no the Green ones: Magenta All three the cone types excited: White You can of course distinguish much more colors than these 8 because each receptor type can have different levels of excitement. Color blindness means one or more of the color types of cones are missing or less sensitive, for example if you miss the red one, you can only see the difference between light that has mainly green and light that has mainly blue. Light with mainly red, will show up as green for such a person, because the green receptors are still more sensitive to red than the blue ones.

People who have 2 types of cones missing, and have thus only one type left, see in black and white, because only two main types of signals now exist: "the cone is excited" and "the cone is not excited". Imagine how much more colors a human would be able to see if he had 4 types of color receptors instead of only 3. One final question remains: violet is on one side of the spectrum, while red is totally on the other side. Violet is much closer to the blue receptors of the eye than the red ones, so you'd think violet light would look like pure blue to the eye. But violet looks a bit more like purple, hinting that it has some red in it, why could that be? The reason is that violet has such a high frequency, too high for the blue receptor as well, that the signal is very weak for both the blue and the red receptor. Relatively speaking, the red and blue signal will thus be pretty close to each other, and the color will show up more like purple than like blue for the brain!

The RGB Color Model The RGB color model works exactly like those color receptors of the human eye work: the RGB color model describes a color by using 3 variables, Red, Green and Blue. These variables can be compared to the strength of the signals from the 3 types of color receptors in the nerves. A computer or TV screen works this way too: it has 3 types of cells, Red, Green and Blue, and can make each type brighter or darker independently, exciting the correct receptors of the eye to create the desired color. If you look with a magnifying glass to a white area of your computer screen, you can see that the color white is actually made out of the 3 colors red, green and blue. This means the white emitted by a computer screen is different from white sunlight: while white sunlight contains photons of all frequencies (except a few), the computer screen only has 3 frequencies. The human eye can't see the difference between these two kinds of white. The RGB color model is the one you'll mostly be dealing with in computer graphics. It's also called the additive color model, because you add 3 color components together to form any color.

In 24-bit color, each of the 3 components R, G and B is an 8-bit variable that can be an integer number between 0 and 255. 0 means the color component is off (black), while 255 means it's at its full intensity. 127 is half intensity. This means color 0,0,0 is the darkest black, color 255,0,0 is the brightest red, color 0,255,0 is the brightest green and color 0,0,255 is the brightest blue. 255,255,255 is the brightest white and 127,127,127 is gray. 32-bit color is the same but with an extra 8-bit alpha channel added that can be used for transparency of textures, ...

The RGB color model isn't very intuitive, so here's a table containing some common RGB values: Here is a table with common RGB color values: R FFFFFF White This way, you should be able to guess that 128,0,0 is dark red, 255,128,192 is pink and 16,16,16 is very dark gray. The Hex value is the hexadecimal code of the color, used for example in HTML. The R, G and B values are the ones to fill in as parameters for functions of QuickCG like pset, drawLine, drawCircle to give the color. In RGB color, the higher the values of R, G and B, the brighter the color will be, and if R=G=B, the color will be a shade of gray. If you set R=x, G=y, B=z, you can represent RGB color on a cube, where the origin is black and the corner at R=255,G=255,B=255 is white: RGB Arithmetic By doing calculations on the RGB values of the pixels of an image you can perform various color effects.

Here's a table of the operations you can do with RGB color, screenshots and code will follow in the next sections. These operations are given for the 24-bit color model with 8 bit per channel, so 255 is the maximum value of a color. Colors channels can also be represented as floating point numbers between 0.0 and 1.0, then you have to replace the value "255" by "1.0". C represents the channel together or the total color, while R, G and B represent the Red, Green and Blue channel separately. Operation Swap the values of two color channels to get an image with a completely different color. We'll try all these formulas on the following PNG image of a flower: Negative Image The following code will load a PNG image of 200*133 pixels, calculate its negative, and display the result. ColorRGB is the struct containing 3 integers r, g and b, to describe the rgb color.

int main(int argc, char *argv[]) { unsigned long w = 0, h = 0; std::vector&ltColorRGB> image; loadImage(image, w, h, "pics/flower.png"); screen(w, h, 0, "RGB Color"); ColorRGB color; //the color for the pixels for(int y = 0; y < h; y++) for(int x = 0; x < w; x++) { //here the negative color is calculated! color.r = 255 - image[y * w + x].r; color.g = 255 - image[y * w + x].g; color.b = 255 - image[y * w + x].b; pset(x, y, color); } redraw(); sleep(); return 0; } image[y * w + x].r is the red component of pixel x, y of the image, so 255 - image[y * w + x].r is the negative of it. This is done for each color channel.

Here's the result: You could as well have typed "color = RGB_White - image[y * w + x]" instead of the 3 lines of code, because the ColorRGB struct supports a few operators. Change the Brightness To change the brightness, divide R, G and B through a number larger than 1 to make it darker, or multiply them with that number to make it brighter. If the color component becomes higher than 255, truncate it to 255.

For example, to make the image double as dark, change the 3 lines of code that made the image negative in the previous example, to: color.r = image[y * w + x].r / 2; color.g = image[y * w + x].g / 2; color.b = image[y * w + x].b / 2; Or to make it 1.5 times as dark, use: color.r = int(image[y * w + x].r / 1.5); color.g = int(image[y * w + x].g / 1.5); color.b = int(image[y * w + x].b / 1.5); To make it twice as bright, use: color.r = image[y * w + x].r * 2; color.g = image[y * w + x].g * 2; color.b = image[y * w + x].b * 2; if(color.r > 255) color.r = 255; if(color.g > 255) color.g = 255; if(color.b > 255) color.b = 255; Instead of dividing or multiplying, you can

 also add or subtract a number instead, this even gives better results when making it brighter: color.r = image[y * w + x].r + 50; color.g = image[y * w + x].g + 50; color.b = image[y * w + x].b + 50; if(color.r > 255) color.r = 255; if(color.g > 255) color.g = 255; if(color.b > 255) color.b = 255; Or darker: color.r = image[y * w + x].r - 50; color.g = image[y * w + x].g - 50; color.b = image[y * w + x].b - 50; if(color.r < 0) color.r = 0; if(color.g < 0) color.g = 0; if(color.b < 0) color.b = 0; Greyscale One way to grayscale an image is to calculate a weighed average (here based in ITU Rec.

709) of the 3 color components and use this average as the value for the shade of gray. The eye is less sensitive to blue, so it gets a smaller coefficient, and more to green so it gets a larger one: color.r = color.g = color.b = 0.2126 * image[y * w + x].r + 0.7152 * image[y * w + x].g + 0.0722 * image[y * w + x].b; Swapping and Removing Channels By removing channels, you completely remove a color of the image, for example if you remove the red of the flower you get this: color.r = 0; //red component set to zero color.g = image[y * w + x].g; color.b = image[y * w + x].b; If you remove green instead, you get: And if you remove blue, you get: The last image looks quite similar to the original because there wasn't much blue in the image, though white areas now look green or yellow, and everything has become a bit darker.

Swapping two channels can give results with a totally different color, for example if we swap the red and green channel the flower becomes green while the background becomes reddish: color.r = image[y * w + x].g; //the green component of the image color.g = image[y * w + x].r; //the red component of the image color.b = image[y * w + x].b; //the blue component of the image And if red and blue are swapped instead, the flower becomes of course blue: To make the flower yellow, set both R and G to the red channel of the image: color.r = image[y * w + x].r; //the red component of the image color.g = image[y * w + x].r; //the red component of the image color.b = image[y * w + x].b; //the blue component of the image The HSL Color Model HSL is another way to describe color with 3 parameters. RGB is the way computer screens work, but not very intuitive. HSL is more intuitive, but you need to convert it to RGB before you can draw a pixel with it.

The nicest application of this color model is that you can easily create rainbow gradients or change the color, lightness or saturation of an image with this color model. HSL color obviously has the parameters H, S and L, or Hue, Saturation and Lightness. Hue indicates the color sensation of the light, in other words if the color is red, yellow, green, cyan, blue, magenta, ... This representation looks almost the same as the visible spectrum of light, except on the right is now the color magenta (the combination of red and blue), instead of violet (light with a frequency higher than blue): Hue works circular, so it can be represented on a circle instead. A hue of 360° looks the same again as a hue of 0°. Saturation indicates the degree to which the hue differs from a neutral gray. The values run from 0%, which is no color, to 100%, which is the fullest saturation of a given hue at a given percentage of illumination. The more the spectrum of the light is concentrated around one wavelength, the more saturated the color will be.

Lightness indicates the illumination of the color, at 0% the color is completely black, at 50% the color is pure, and at 100% it becomes white. In HSL color, a color with maximum lightness (L=255) is always white, no matter what the hue or saturation components are. Lightness is defined as (maxColor+minColor)/2 where maxColoris the R, G or B component with the maximum value, and minColor the one with the minimum value. Please note that the lightness of HSL and HSV is not a good approximation of the actual perceived lightness, a linear combination such as 0.2126*R + 0.7152*G + 0.0722*B or 0.299*R + 0.587*G + 0.114*B is more precise. HSL and HSV are easy to use color models but do not attempt to model the human visual system well. See the end of this tutorial for other color models.

In this tutorial, Hue, Saturation and Lightness will be presented as numbers between 0-255 instead, so that the HSL model has the same 24 bits as the RGB model. The HSL color model is for example used in Paint Shop Pro's color picker. The HSV Color Model The HSV color model (sometimes also called HSB), uses the parameter Value instead of Lightness. Value works different than Lightness, in that the color with maximum value (V=255) can be any color like red, green, yellow, white, etc..., at its maximum brightness. Value is defined as maxColor, where maxColor is the R, G or B component with the maximum value. So the colors red (255,0,0) and white (255,255,255) both have a Value of 255 indeed. In HSL, the Lightness showed the following behavior when increased: In HSV, Value does the following: The Hue and Saturation parameters work very similar to the ones in HSL. HSV is generally better at representing the saturation, while HSL is better at representing the brightness.

However, HSV is again better to decrease the brightness of very bright images. We can compare the HSL and HSV model a bit better by comparing their plots: Here is the plot of HSL (left) and HSV (right) with S=255, Hue on the horizontal axis, and Lightness/Value on the vertical axis (maximum lightness at the top): While the top of the HSL curve is white because white is the color with maximum brightness, the top of the HSV curve contains all colors, because the saturation is 255 and in HSV, saturation 255 has to be a color while white should have 0 saturation. The top of the HSV curve is the same as the center horizontal line of the HSL curve, and the complete HSV curve is exactly the same as the bottom half of the HSL picture. Here is the plot of HSL (left) and HSV (right) with L=255 and V=255 respectively, Hue on the horizontal axis, and Saturation on the vertical axis (maximum saturation at the bottom): The HSL curve is completely white, because white is the only color with L=255 in the HSL model.

The HSV curve, now shows all colors that have one or more of their color components equal to 255. The HSV picture here, is exactly the same as the top half of the previous HSL picture where S=255. And here's the plot of HSL (left) and HSV (right) with L=128 and V=128 respectively, and again Hue on the horizontal axis, and Saturation on the vertical axis (maximum saturation at the bottom): Color Model Conversions To draw the plots given above, color model conversion functions have to be used: first you describe the color as HSL or HSV, but to plot it on screen, it has to be converted to RGB first. Transformations from RGB to HSL/HSV are handy as well, for example if you load an RGB image and want to change it hue, you have to convert it to HSL or HSV first, then change the hue, and then change it back to RGB. The color model conversion formulas are already in QuickCG, in the QuickCG.cpp file. RGB to HSL The following function converts from RGB color to HSL color. You give it a ColorRGB and it returns a ColorHSL.

Both ColorRGB and ColorHSL are simple structs with 3 integers, the only difference is their names. The RGBtoHSL function calculates the values for ColorHSL. First the variables r, g, b, h, s, l are declared as floating point numbers. Internally, the function works with floating point numbers between 0.0 and 1.0, for better precision. At the end of the function, the results can very easily be converted back to integers from 0-255. The function can also easily be modified to work with other ranges, e.g. if you'd want to use 16 bit per color channel, or represent Hue as a value between 0° and 360°. ColorHSL RGBtoHSL(ColorRGB colorRGB) { float r, g, b, h, s, l; //this function works with floats between 0 and 1 r = colorRGB.r / 256.0; g = colorRGB.g / 256.0; b = colorRGB.b / 256.0; Then, minColor and maxColor are defined.

Mincolor is the value of the color component with the smallest value, while maxColor is the value of the color component with the largest value. These two variables are needed because the Lightness is defined as (minColor + maxColor) / 2. float maxColor = max(r, max(g, b)); float minColor = min(r, min(g, b)); If minColor equals maxColor, we know that R=G=B and thus the color is a shade of gray. This is a trivial case, hue can be set to anything, saturation has to be set to 0 because only then it's a shade of gray, and lightness is set to R=G=B, the shade of the gray. //R == G == B, so it's a shade of gray { h = 0.0; //it doesn't matter what value it has s = 0.0; l = r; //doesn't matter if you pick r, g, or b } If minColor is not equal to maxColor, we have a real color instead of a shade of gray, so more calculations are needed: Lightness (l) is now set to its definition of (minColor + maxColor)/2.

Saturation (s) is then calculated with a different formula depending if light is in the first half of the second half. This is because the HSL model can be represented as a double cone, the first cone has a black tip and corresponds to the first half of lightness values, the second cone has a white tip and contains the second half of lightness values. Hue (h) is calculated with a different formula depending on which of the 3 color components is the dominating one, and then normalized to a number between 0 and 1.

else { l = (minColor + maxColor) / 2; if(l < 0.5) s = (maxColor - minColor) / (maxColor + minColor); else s = (maxColor - minColor) / (2.0 - maxColor - minColor); if(r == maxColor) h = (g - b) / (maxColor - minColor); else if(g == maxColor) h = 2.0 + (b - r) / (maxColor - minColor); else h = 4.0 + (r - g) / (maxColor - minColor); h /= 6; //to bring it to a number between 0 and 1 if(h < 0) h ++; } Finally, H, S and L are calculated out of h,s and l as integers between 0 and 255 and "returned" as the result. Returned, because H, S and L were passed by reference to the function.

ColorHSL colorHSL; colorHSL.h = int(h * 255.0); colorHSL.s = int(s * 255.0); colorHSL.l = int(l * 255.0); return colorHSL; } HSL to RGB This is the opposite conversion, so this function will calculate the inverse of the RGBtoHSL function. First, internally the variables with small letters are defined as floating point numbers between 0 and 1 again. Some temporary values for the calculations are also declared. ColorRGB HSLtoRGB(ColorHSL colorHSL) { float r, g, b, h, s, l; //this function works with floats between 0 and 1 float temp1, temp2, tempr, tempg, tempb; h = colorHSL.h / 256.0; s = colorHSL.s / 256.0; l = colorHSL.l / 256.0; Then follows a trivial case: if the saturation is 0, the color will be a grayscale color, and the calculation is then very simple: r, g and b are all set to the lightness.

//If saturation is 0, the color is a shade of gray if(s == 0) r = g = b = l; If the saturation is higher than 0, more calculations are needed again. red, green and blue are calculated with the formulas defined in the code.

//If saturation > 0, more complex calculations are needed else { //Set the temporary values if(l < 0.5) temp2 = l * (1 + s); else temp2 = (l + s) - (l * s); temp1 = 2 * l - temp2; tempr = h + 1.0 / 3.0; if(tempr > 1) tempr--; tempg = h; tempb = h - 1.0 / 3.0; if(tempb < 0) tempb++; //Red if(tempr < 1.0 / 6.0) r = temp1 + (temp2 - temp1) * 6.0 * tempr; else if(tempr < 0.5) r = temp2; else if(tempr < 2.0 / 3.0) r = temp1 + (temp2 - temp1) * ((2.0 / 3.0) - tempr) * 6.0; else r = temp1; //Green if(tempg < 1.0 / 6.0) g = temp1 + (temp2 - temp1

) * 6.0 * tempg; else if(tempg < 0.5) g = temp2; else if(tempg < 2.0 / 3.0) g = temp1 + (temp2 - temp1) * ((2.0 / 3.0) - tempg) * 6.0; else g = temp1; //Blue if(tempb < 1.0 / 6.0) b = temp1 + (temp2 - temp1) * 6.0 * tempb; else if(tempb < 0.5) b = temp2; else if(tempb < 2.0 / 3.0) b = temp1 + (temp2 - temp1) * ((2.0 / 3.0) - tempb) * 6.0; else b = temp1; } And finally, the results are returned as integers between 0 and 255.

ColorRGB colorRGB; colorRGB.r = int(r * 255.0); colorRGB.g = int(g * 255.0); colorRGB.b = int(b * 255.0); return colorRGB; } RGB to HSV The function RGBtoHSV works very similar as the RGBtoHSL function, the only difference is that now the variable V (Value) instead of L (Lightness) is used, and Value is defined as maxColor. This can immediately be calculated at the beginning of the function: ColorHSV RGBtoHSV(ColorRGB colorRGB) { float r, g, b, h, s, v; //this function works with floats between 0 and 1 r = colorRGB.r / 256.0; g = colorRGB.g / 256.0; b = colorRGB.b / 256.0; float maxColor = max(r, max(g, b)); float minColor = min(r, min(g, b)); v = maxColor; Then, the saturation is calculated. If the color is black, the value of saturation doesn't matter so it can be set to 0.

This has to be done to avoid a division by zero. if(maxColor == 0) //avoid division by zero when the color is black { s = 0; } else { s = (maxColor - minColor) / maxColor; } Finally, the hue is calculated. If saturation is 0, the color is gray so hue doesn't matter. Again this case is handled separately to avoid divisions by zero. if(s == 0) { h = 0; //it doesn't matter what value it has } else { if(r == maxColor) h = (g - b) / (maxColor-minColor); else if(g == maxColor) h = 2.0 + (b - r) / (maxColor - minColor); else h = 4.0 + (r - g) / (maxColor - minColor); h /= 6.0; //to bring it to a number between 0 and 1 if (h < 0) h++; } And finally, the results are returned as integers between 0 and 255.

ColorHSV colorHSV; colorHSV.h = int(h * 255.0); colorHSV.s = int(s * 255.0); colorHSV.v = int(v * 255.0); return colorHSV; } HSV to RGB First the floating point numbers between 0 and 1 are declared again: ColorRGB HSVtoRGB(ColorHSV colorHSV) { float r, g, b, h, s, v; //this function works with floats between 0 and 1 h = colorHSV.h / 256.0; s = colorHSV.s / 256.0; v = colorHSV.v / 256.0; The trivial case for saturation = zero is handled: //If saturation is 0, the color is a shade of gray if(s == 0) r = g = b = v; The HSV model can be presented on a cone with hexagonal shape.

For each of the sides of the hexagon, a separate case is calculated: //If saturation > 0, more complex calculations are needed else { float f, p, q, t; int i; h *= 6; //to bring hue to a number between 0 and 6, better for the calculations i = int(floor(h)); //e.g.

2.7 becomes 2 and 3.01 becomes 3 or 4.9999 becomes 4 f = h - i; //the fractional part of h p = v * (1 - s); q = v * (1 - (s * f)); t = v * (1 - (s * (1 - f))); switch(i) { case 0: r = v; g = t; b = p; break; case 1: r = q; g = v; b = p; break; case 2: r = p; g = v; b = t; break; case 3: r = p; g = q; b = v; break; case 4: r = t; g = p; b = v; break; case 5: r = v; g = p; b = q; break; } } And again, the results are "returned" as integers between 0 and 255.

ColorRGB colorRGB; colorRGB.r = int(r * 255.0); colorRGB.g = int(g * 255.0); colorRGB.b = int(b * 255.0); return colorRGB; } HSL and HSV Arithmetic The functions given above are already in the QuickCG, and thanks to them we can do HSL and HSV arithmetic on images. The examples will be performed on the flower image again: Changing Hue It doesn't matter if you change hue with the HSL or HSV model, the results are the same, so for no particular reason at all let's do it with HSL here.

The following code will load the PNG image, convert it to HSL, change the Hue by adding a certain value to it, and convert it back to RGB to display it (put this code in the main function in the main.cpp file): int main(int argc, char *argv[]) { ColorRGB colorRGB; ColorHSL colorHSL; unsigned long w, h; std::vector&ltColorRGB> image; loadImage(image, w, h, "pics/flower.png"); screen(w, h, 0, "RGB Color"); for(int y = 0; y < h; y++) for(int x = 0; x < w; x++) { //store the color of the image in variables R, G and B colorRGB = image[y * w + x]; //calculate H, S and L out of R, G and B colorHSL = RGBtoHSL(colorRGB); //change Hue colorHSL.h += int(42.5 * 1); colorHSL.h %= 255; //convert back to RGB colorRGB = HSLtoRGB(colorHSL); //plot the pixel pset(x, y, colorRGB); } redraw(); sleep(); return 0; } The Hue

 is modulo divided through 255, because it has to be between 0 and 255, and it's circular, so a hue of 260 is the same as a hue of 5.

The value 42.5 was chosen to be 255/6, representing a hue shift of 60°. Here are screenshots of the result for a hue shift of 0°, 60°, 120°, 180°, 240° and 300° (360° gives the same result as 0° again): You can also set Hue to a constant, to give the whole image the same color. For example, here hue is set to 25, which is orange: Changing Saturation You can change the saturation to make the image more colorful, or more like pastel, or grayscale. This time, the results are slightly different if you use the HSL or HSV color model. For example, to increase the saturation by multiplying it with 2.5, change the lines of the code that changed the hue to: colorHSV.s = int(colorHSV.s * 2.5); if(colorHSV.s > 255) colorHSV.s = 255; If Saturation is higher than 255, it's truncated.

On the left is the result if you use HSL, on the right if you use HSV. The result is pretty similar to the original image because the saturation in it was quite high already. Only the background became a bit more green. If you multiply it with 0.5 instead, you'll decrease the saturation by halving it: You can also decrease the saturation by substracting a value from it instead: colorHSV.s = colorHSV.s - 100; if(colorHSV.s < 0) colorHSV.s = 0; The background will be grayscale now, while the flower with its high saturation still has some color: If saturation is set to 0, the image will be grayscale, in a different way if you use HSL or HSV, and both are also different from the "average" formula to grayscale an image: And this is what you get if you set saturation equal to 128 for all pixels. The flower and background look equally colorful now: Changing Brightness Finally, HSL and HSV can also be used to change the brightness of an image. Again, the HSL and HSV model will work differently. HSL gives bad result when making an image with white or near white pixels darker.

You can also decrease the saturation by substracting a value from it instead: colorHSV.l -= 50; if(colorHSV.l < 0) colorHSV.l = 0; Here's the result for HSL on the left and HSV on the right: And setting brightness equal to 192 for all pixels gives: Gammma Correction Gamma correction is done by raising the components to a power, but scaled to range 0-1 instead of 0-255, producing a new value in range 0-1. For typical computer monitors, the value of the power is, roughly speaking, 2.2. When color values correspond to the amount of light, this is called "linear" RGB color. However, in images, the color is usually not stored in the linear format, but gamma compressed with a power of 1 / 2.2. This works because computer screens do the opposite transform automatically, having the effect of raising to a power 2.2. When doing operations on the pixels of an image, for correctness, these should be done in linear RGB, not compressed RGB, otherwise the non-linear color values affect your intended linear or other transformation (e.g. averaging two neighboring pixels).

The rest of these tutorials actually forgot this fact (e.g. the one about filtering), but it's something to take into account in real worls applications.

So, to convert from compressed RGB to linear RGB, before doing operations: color.r = 255.0 * std::pow(image[y * w + x].r / 255.0, 2.2); color.g = 255.0 * std::pow(image[y * w + x].g / 255.0, 2.2); color.b = 255.0 * std::pow(image[y * w + x].b / 255.0, 2.2); And to convert back: image[y * w + x].r = 255.0 * std::pow(color.r / 255.0, 1 / 2.2); image[y * w + x].g = 255.0 * std::pow(color.g / 255.0, 1 / 2.2); image[y * w + x].b = 255.0 * std::pow(color.b / 255.0, 1 / 2.2); Other Color Models This article focused on the RGB, HSL and HSV color models.

However, there are a lot more, with various professional applications, such as television, publishing, data compression, ... In addition, careful math is required, and aspects have to be taken into account such as: gamma correction (mentioned above), the whitepoint, the human visual system, color gamut, chromaticity diagram... This is however beyond the scope of this tutorial. Working with these color spaces is best done with floating point numbers, using byte values 0-255 would cause loss of precision. A good resource with exact math is Bruce Lindeboom's website: . We'll finish with a brief list of some other color models, without providing conversion formulas here. RGB: red, green, blue. Exists because the eye has red, green and blue receptors. Most screens also use this model. There exist many different RGB models, differing in the range of red, green and blue (resulting in a certain gamut). The most common one for computer monitors is sRGB. HSL: hue, saturation, lightness, as explained above. HSV: hue, saturation, value, as explained above.

CMY: cyan, magenta, yellow: the additive color model, as opposed to subtractive RGB: with cyan, yellow and magenta ink on white paper, in theory any color can be printed. CMYK: cyan, magenta, yellow, black ("key"): Adding black ink to CMY to allow printers to create more vivid black than mixing three colors together. XYZ: standardized color space CIE 1931. A linear transformation of RGB, based on careful measurements of human vision and designed such that Y corresponds to luminance, and standardized to give XYZ values a real physical meaning that does not depend on screen brightness, etc... Many other CIE based color models (including CIE RGB) can be derived from this. Lab: standardized color space CIE 1976. Non-linear transformation of XYZ, a color-opponent model: L is the lightness, a opposes red and green, b opposes blue and yellow. Very popular color model in professional image editing due to wide gamut and human vision approximation. YUV, YIQ, YCbCr, YPbPr, etc...: Television color models.

Y is the luma or luminance (depending on gamma correction), matching the single component of black-and-white television. The other two components form the chroma, in similar opponent fashion as a and b of Lab. Different television models have different value ranges and different rotations of chroma components in their 2D space. Last edited: 2004

Question: Which colour lies between red and yellow in the visible spectrum
Answer: Orange