Color vision
Color vision is the capacity of an organism or machine to distinguish objects based on the wavelengths (or frequencies) of the light they reflect or emit. The nervous system derives color by comparing the responses to light from the several types of cone photoreceptors in the eye. These cone photoreceptors are sensitive to different portions of the visible spectrum. For humans, the visible spectrum ranges approximately from 380 to 750 nm, and there are normally three types of cones.  The visible range and number of cone types differ between species.
A 'red' apple does not emit red light. Rather, it simply absorbs all the frequencies of visible light shining on it except for a group of frequencies that is perceived as red, which are reflected.  An apple is perceived to be red only because the human eye can distinguish between different wavelengths. Three things are needed to see color: a light source, a detector (e.g. the eye) and a sample to view.
The advantage of color, which is a quality constructed by the visual brain and not a property of objects as such, is the better discrimination of surfaces allowed by this aspect of visual processing.
In order for animals to respond accurately to their environments, their visual systems need to correctly interpret the form of objects around them. A major component of this is perception of colors.

# Physiology of color perception
Perception of color is achieved in mammals through color receptors containing pigments with different spectral sensitivities. In most primates closely related to humans there are three types of color receptors (known as cone cells). This confers trichromatic color vision, so these primates, like humans, are known as trichromats. Many other primates and other mammals are dichromats, and many mammals have little or no color vision.
In the human eye, the cones are maximally receptive to short, medium, and long wavelengths of light and are therefore usually called S-, M-, and L-cones. L-cones are often referred to as the red receptor, but while the perception of red depends on this receptor, microspectrophotometry has shown that its peak sensitivity is in the greenish-yellow region of the spectrum. Similarly, the S- and M-cones do not directly correspond to blue and green, although they are often depicted as such (such as in the graph to the right). It is important to note that the RGB color model is merely a convenient means for representing color, and is not directly based on the types of cones in the human eye.
The peak response of human color receptors varies, even amongst individuals with 'normal' color vision;
in non-human species this polymorphic variation is even greater, and it may well be adaptive.

## Cone cells in the human eye
A range of wavelengths of light stimulates each of these receptor types to varying degrees. Yellowish-green light, for example, stimulates both L and M cones equally strongly, but only stimulates S-cones weakly.  Red light, on the other hand, stimulates L cones much more than M cones, and S cones hardly at all; blue-green light stimulates M cones more than L cones, and S cones a bit more strongly, and is also the peak stimulant for rod cells;
and violet light stimulates almost exclusively S-cones. The brain combines the information from each type of receptor to give rise to different perceptions of different wavelengths of light.
The pigments present in the L and M cones are encoded on the X chromosome; defective encoding of these leads to the two most common forms of color blindness. The OPN1LW gene, which codes for the pigment that responds to yellowish light, is highly polymorphic (a recent study by Verrelli and Tishkoff, 2004, found 85 variants in a sample of 236 men), so up to ten percent of women have an extra type of color receptor, and thus a degree of tetrachromatic color vision. Variations in OPN1MW, which codes for the bluish-green pigment, appear to be rare, and the observed variants have no effect on spectral sensitivity.

## Color in the human brain
Color processing begins at a very early level in the visual system (even within the retina) through initial color opponent mechanisms. Opponent mechanisms refer to the opposing color effect of red-green, blue-yellow, and light-dark. Visual information is then sent back via the optic nerve to the optic chiasm: a point where the two optic nerves meet and information from the temporal (contralateral) visual field crosses to the other side of the brain. After the optic chiasm the visual fiber tracts are referred to as the optic tracts, which enter the thalamus to synapse at the lateral geniculate nucleus (LGN). The LGN is segregated into six layers: two magnocellular (large cell) achromatic layers (M cells) and four parvocellular (small cell) chromatic layers (P cells). Within the LGN P-cell layers there are two chromatic opponent types: red vs. green and blue vs. green/red.
After synapsing at the LGN, the visual tract continues on back toward the primary visual cortex (V1) located at the back of the brain within the occipital lobe. Within V1 there is a distinct band (striation). This is also referred to as "striate cortex", with other cortical visual regions referred to collectively as "extrastriate cortex".It is at this stage that color processing becomes much more complicated.
In V1 the simple three-color segregation begins to break down. Many cells in V1 respond to some parts of the spectrum better than others, but this "color tuning" is often different depending on the adaptation state of the visual system. A given cell that might respond best to long wavelength light if the light is relatively bright might then become responsive to all wavelengths if the stimulus is relatively dim. Because the color tuning of these cells is not stable, some believe that a different, relatively small, population of neurons in V1 is responsible for color vision. These specialized "color cells" often have receptive fields that can compute local cone ratios. Such "double-opponent" cells were initially described in the goldfish retina by Nigel Daw; their existence in primates was suggested by David Hubel and Torsten Wiesel and subsequently proven by Bevil Conway. As Margaret Livingstone and David Hubel showed, double opponent cells are clustered within localized regions of V1 called blobs, and are thought to come in two flavors, red-green and blue-yellow. Red-green cells compare the relative amounts of red-green in one part of a scene with the amount of red-green in an adjacent part of the scene, responding best to local color contrast (red next to green). Modeling studies have shown that double-opponent cells are ideal candidates for the neural machinery of color constancy explained by Edwin H. Land in his retinex theory.
From the V1 blobs, color information is sent to cells in the second visual area, V2. The cells in V2 that are most strongly color tuned are clustered in the "thin stripes" that, like the blobs in V1, stain for the enzyme cytochrome oxidase (separating the thin stripes are interstripes and thick stripes, which seem to be concerned with other visual information like motion and high-resolution form).  Neurons in V2 then synapse onto cells in area V4. Area V4 is a relatively large visual area, the largest by far cortical area outside V1, encompassing almost as much cortex as V1. Neurons in V4 were originally proposed by Semir Zeki to be exclusively dedicated to color, but this has since been shown not to be the case. Quantitative studies have argued that there is no higher concentration of color cells in V4 than in primary visual cortex, although this remains controversial. Independent of color sensitivity, V4 neurons have been shown to be very sensitive to the shape of stimuli, curvature, and stereo-scopic depth. V4 neurons have also been shown to be modulated by attention. The role of V4 neurons in color vision remains to be better characterized: indeed the vast majority of scientific papers examining the function of V4 do not concern color processing.
Anatomical studies have shown that neurons in V4 provide input to the inferior temporal lobe . "IT" cortex is thought to integrate color information with shape and form, although it has been difficult to define the appropriate criteria for this claim. Despite this murkiness, it has been useful to characterize this pathway (V1 > V2 > V4 > IT) as the ventral stream or the "what pathway", distinguished from the dorsal stream ("where pathway") that is thought to analyze motion, among many other features.

## In other animals
Other animals may have more complex color vision systems than humans (for review see Kelber et al. 2003). These are many tropical fish and birds. In the latter case tetrachromacy is achieved through up to four cone types, depending on species. Brightly colored oil droplets inside the cones shift or narrow the spectral sensitivity of the cell. It has been suggested that it is likely that pigeons are pentachromats. Mammals other than primates generally have less effective two-receptor color perception systems, allowing only dichromatic color vision; marine mammals have only a single cone type and are thus monochromats. Many invertebrates have color vision. Honey- and bumblebees have trichromatic color vision, which is insensitive to red but sensitive in ultraviolet to a color called bee purple. Papilio butterflies apparently have tetrachromatic color vision despite possessing six photoreceptor types (Arikawa 2003). The most complex color vision system in animal kingdom has been found in stomatopods with up to 12 different spectral receptor types (Cronin & Marshall 1989) which are thought to work as multiple dichromatic units.

# Evolution
Color perception mechanisms are highly dependent on evolutionary factors, of which the most prominent is thought to be satisfactory recognition of food sources. In herbivorous primates, color perception is essential for finding proper (mature) leaves. In hummingbirds, particular flower types are often recognized by color as well. On the other hand, nocturnal mammals have less-developed color vision, since adequate light is needed for cones to function properly. There is evidence that ultraviolet light plays a part in color perception in many branches of the animal kingdom, especially insects.
Trichromatic color vision evolved in the ancestors of modern monkeys, apes, and humans as they switched to diurnal (daytime) activity and consumption of fruits from flowering plants.

# Mathematics of color perception
A "physical color" is a combination of pure spectral colors (in the visible range).  Since there are, in principle, infinitely many distinct spectral colors, the set of all physical colors may be thought of as an infinite-dimensional vector space, in fact a Hilbert space.  We call this space Hcolor. More technically, the space of physical colors may be considered to be the (mathematical) cone over the simplex whose vertices are the spectral colors.
An element C of Hcolor is a function from the range of visible wavelengthsconsidered as an interval of real numbers to the real numbers, assigning to each wavelength w in  its intensity C(w).
A humanly perceived color may be modeled as three numbers: the extents to which each of the 3 types of cones is stimulated. Thus a humanly perceived color may be thought of as a point in 3-dimensional Euclidean space. We call this space R3color.
Since each wavelength w stimulates each of the 3 types of cone cells to a known extent, these extents may be represented by 3 functions s(w), m(w), l(w) corresponding to the response of the S, M, and L cone cells, respectively.
Finally, since a beam of colored light can be composed of many different wavelengths, to determine the extent to which a physical color C in Hcolor stimulates each cone cell, we must calculate the integral (with respect to w), over the interval , of C(w)*s(w), of C(w)*m(w), and of C(w)*b(w). The triple of resulting numbers associates to each physical color C (which is a region in Hcolor) to a particular perceived color (which is a single point in R3color). This association is easily seen to be linear. It may also easily be seen that many different regions in the "physical" space Hcolor can all result in the same single perceived color in R3color, so a perceived color is not unique to one physical color.
Thus human color perception is determined by a specific, non-unique linear mapping from the infinite-dimensional Hilbert space Hcolor to the 3-dimensional Euclidean space R3color.
Technically, the image of the (mathematical) cone over the simplex whose vertices are the spectral colors, by this linear mapping, is also a (mathematical) cone in R3color.  Moving directly away from the vertex of this cone represents maintaining the same chromaticity while increasing its intensity. Taking a cross-section of this cone yields a 2D chromaticity space.  Both the 3D cone and its projection or cross-section are convex sets; that is, any mixture of spectral colors is also a color.
In practice, it would be quite difficult to measure an individual's cones' three responses to various physical color stimuli.   So instead, three specific benchmark test lights are typically used; let us call them S, M, and L.  In order to calibrate human perceptual space, scientists allowed human subjects to try to match any physical color by turning dials to create specific combinations of intensities (IS, IM, IL) for the S, M, and L lights, resp., until a match was found.  This needed only to be done for physical colors that are spectral (since a linear combination of spectral colors will be matched by the same linear combination of their (IS, IM, IL) matches).  Note that in practice, often at least one of S, M, L would have to be added with some intensity to the physical test color, and that combination matched by a linear combination of the remaining 2 lights. Across different individuals (without color blindness), the matchings turned out to be nearly identical.
By considering all the resulting combinations of intensities (IS, IM, IL) as a subset of 3-space, a model for human perceptual color space is formed.  (Note that when one of S, M, L had to be added to the test color, its intensity was counted as negative.)  Again, this turns out to be a (mathematical) conenot a quadric, but rather all rays through the origin in 3-space passing through a certain convex set. Again, this cone has the property that moving directly away from the origin corresponds to increasing the intensity of the S, M, L lights proportionately. Again, a cross-section of this cone is a planar shape that is (by definition) the space of "chromaticities" (informally: distinct colors); one particular such cross section, corresponding to constant X+Y+Z of the CIE 1931 color space, gives the CIE chromaticity diagram.
It should be noted that this system implies that for any hue or non-spectral color, there are infinitely many distinct physical spectra that are all perceived as that hue or color. So, in general there is no such thing as the combination of spectral colors that we perceive as (say) yellow-green; instead there are infinitely many possibilities.
The CIE chromaticity diagram is horseshoe-shaped, with its curved edge corresponding to all spectral colors (the spectral locus), and the remaining straight edge corresponding to the most saturated purplesmixtures of red and violet.

# Chromatic adaptation
An object may be viewed under various conditions. For example, it may be illuminated by sunlight, the light of a fire, or a harsh electric light. In all of these situations, human vision perceives that the object has the same color: an apple always appears red, whether viewed at night or during the day. On the other hand, a camera with no adjustment for light may register the apple as having varying color. This feature of the visual system is called chromatic adaptation, or color constancy; when the correction occurs in a camera it is referred to as white balance.
Chromatic adaptation is one aspect of vision that may fool someone into observing a color-based optical illusion, such as the same color illusion.
Though the human visual system generally does maintain constant perceived color under different lighting, there are situations where the relative brightness of two different stimuli will appear reversed at different illuminance levels. For example, the bright yellow petals of flowers will appear dark compared to the green leaves in dim light while the opposite is true during the day. This is known as the Purkinje effect, and arises because the peak sensitivity of the human eye shifts toward the blue end of the spectrum at lower light levels.

## Von Kries transform
The von Kries chromatic adaptation method is a technique that is sometimes used in camera image processing.  The method is to apply a gain to each of the human cone cell spectral sensitivity responses so as to keep the adapted appearance of the reference white constant.  The application of Johannes von Kries's idea of adaptive gains on the three cone cell types was first explicitly applied to the problem of color constancy by Herbert E. Ives, and the method is sometimes referred to as the Ives tranform or the von KriesIves adaptation.
The von Kries coefficient rule rests on the assumption that color constancy is achieved by individually adapting the gains of the three cone responses, the gains depending on the sensory context, that is, the color history and surround. Thus, the cone responses c' from two radiant spectra can be matched by appropriate choice of diagonal adaptation matrices D_1 and D_2:
where S is the cone sensitivity matrix and f is the spectrum of the conditioning stimulus. This leads to the von Kries transform for chromatic adaptation in LMS color space (responses of long-, medium-, and short-wavelength cone response space):
This diagonal matrix D maps cone responses, or colors, in one adaptation state to corresponding colors in another; when the adaptation state is presume to be determined by the illuminant, this matrix is useful as an illuminant adaptation transform. The elements of the diagonal matrix D are the ratios of the cone responses (Long, Medium, Short) for the illuminant's white point.
The more complete von Kries transform, for colors represented in XYZ or RGB color space, includes matrix transformations into and out of LMS space, with the diagonal transform D in the middle.