\documentclass[a4paper,11pt]{article}

% Definitions for the document
\def \Course {Interactive Computer Graphics }
\def \LectureNo {4}
% font definitions used in vector algebra
\newcommand{\Vector}[1]{\mathbf{#1}}
\newcommand{\UVector}[1]{\textbf{\em #1}}
\newcommand{\Matrix}[1]{\mathcal{#1}}
% standard layout for Duncan's lecture notes and tutorial material
\usepackage[margin=2cm, nohead]{geometry}
\usepackage{times}
\usepackage{wrapfig}
\usepackage{subfigure}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{amsfonts}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\renewcommand{\footrulewidth}{0.4pt}
\renewcommand{\headrulewidth}{0pt}
\lfoot{\footnotesize{\Course Lecture \LectureNo}}
\rfoot{\footnotesize{\thepage}}
% end of standard layout


\begin{document}

\section*{Lecture \LectureNo: Colour}

\subsection*{The physical description of colour}


Colour vision is a very complicated biological and psychological  phenomenon.  It can be described in many different ways, including by physics, by subjective observation, or by the tri-stimulus representation commonly used in computers. As we noted previously, light has a wavelength ($\lambda$), which can be measured accurately, and an energy or intensity.  Lasers produce light of one particular wavelength, but generally visible light is a distribution of energy into a band of wavelengths. Figure \ref{Fig:RedLigntDistribution} shows a distribution of light energy which we would perceive as red in colour, and figure \ref{Fig:SunlightDistribution} shows the the distribution of energy found in sunlight, which we perceive as light yellow. The wavelength range of the visible spectrum is approximately from 400 to 700 nano-meters.
\begin{figure}[h]
\subfigure[Red light]
{   \includegraphics[width=80mm]{Figures/GraphicsColourRedLightDistribution.jpg} 
    \label{Fig:RedLigntDistribution}
}
\subfigure[Sunlight]
{ \includegraphics[width=80mm]{Figures/GraphicsColourSunlightDistribution.jpg} 
  \label{Fig:SunlightDistribution}
}
\caption{Energy Distributions for light}
\end{figure}

In the eye we have just three distinct 'cone' cells for detecting light energy. These respond to a band of wavelength centred around red (600), green (560) and blue (440); respectively.  The bands overlap, so, for example green light excites all three types. Typical responses of the cone cells are shown in figure \ref{Fig:ConeReceptors} The consequence of this is that each type of cell may be excited similarly from very different energy distributions. Any distribution of wavelengths will be perceived by us as a single colour, but two entirely different distributions of intensities could be perceived as the same colour.

\subsection*{Subjective observation of colour}
\begin{wrapfigure}{r}{70mm}
  \vspace{-10mm}
  \begin{center}
     \includegraphics[width=70mm]{Figures/GraphicsColourConeReceptors.jpg} 
  \end{center}
  \vspace{-8mm}
  \caption{Typical responses of individual cone cells}
   \vspace{5mm}
  \label{Fig:ConeReceptors}
\end{wrapfigure}
Two colours are said to be equivalent when an observer says that they are equivalent. Selecting three pure light sources (R, G, B) and mixing them together while varying their respective intensities, it is possible to create a large number of colours. Each colour satisfies the following linear combination: $X = r + g + b$ where $r, g, b$ are the intensities of the red, green and blue light sources in the mix. One way to approach colour definition is through a matching experiment.  For an unknown colour we can compare it to a mixture $X$, and adjust $r$, $g$ and $b$ until the mixture matches the unknown colour. This technique is limited by the actual colours of the light sources that are mixed, and not all colours can be matched in this way. However, if an unknown colour cannot be matched, then it is always possible add one of the $r, g, b$ light sources to it, and form a match with the other two light sources. This is, in effect, subtracting a colour from the mix. Matching will be possible using one of the three subtractive matching schemes below.
\newline
\begin{tabular}{l l}
   & $X + r  =  g + b$ \\
or & $X + g  =  r + b$ \\
or & $X + b  =  r + g$
\end{tabular}
\newline
The representation of colours as a mixture of three components is called the tri-stimulus representation, and is very commonly used in monitors and other active colour devices. The pure colours used are red green and blue, and are referred to as the additive primary colours.

\subsection*{The Standard Additive Linear System (CIE)}


Matching allows us to determine an rgb representation of any colour, even though the scales include negative numbers. The scales used depend on the wavelengths of the sources for matching and are not standard.	In order to create a manageable standard system, a committee of scientists devised the CIE Chromaticity Diagram, in which colours are specified by a linear combination of three light sources normalised to the positive range [0..1] to avoid any negative values. The three principle colours would normally require a three dimensional diagram, but by using further normalisation a two dimensional diagram is produced.  Suppose a colour is defined, as above, by: $C = r + g + b$. If we divide each component of this equation with $(r+g+b)$ and get a normalised set of coordinates:
\newline
\begin{tabular}{l l l}
    & $x = r/(r+g+b)$ & the normalised red component, \\
    & $y = g/(r+g+b)$ & the normalised green component, \\
    & $z = b/(r+g+b)$ & the normalised blue component, \\
and & $x + y + z = 1$ &
\end{tabular}
\newline
So, knowing two of the three normalised colour components $(x,y)$ the third one can be determined, for example $z=1-x-y$.  

\begin{figure}[h]
\subfigure[Standard Oberver response]
{ \includegraphics[width=53mm]{Figures/GraphicsColourObserverResponse.jpg} 
  \label{Fig:ObserverResponse}
}
\subfigure[Normalised space for colour definition]
{   \includegraphics[width=53mm]{Figures/GraphicsColourCIENormalisedSpace.jpg} 
    \label{Fig:CIENormalisedSpace}
}
\subfigure[The CIE Diagram]
{ \includegraphics[width=53mm]{Figures/GraphicsColourCIEDiagram.jpg} 
  \label{Fig:CIEDiagram}
}
\caption{Defining the CIE Diagram}
\label{Fig:CIEDefinition}
\end{figure}
The process by which the CIE diagram was defined is illustrated in in figure \ref{Fig:CIEDefinition}. First a standard observer response was defined. This takes into account not only the typical responses of the three types of cone cell, shown in figure \ref{Fig:ConeReceptors}, but also the density of the cells in the foveal region of the eye. This standard response is shown in figure \ref{Fig:ObserverResponse} and represents the typical overall cone cell responses to the light arriving in a small solid angel at the eye. Any wavelength in figure \ref{Fig:ObserverResponse} can now be associated with a tri-stimulus value defined by the relative magnitudes of the responses of the three types of cell. For example at the wavelength 580 we can read off the graph that blue is zero and red and greeen are approximately equal at 0.8. The three values are normlised so that they sum to 1 and plotted in a normalised cartesian space which is illustrated by figure \ref{Fig:CIENormalisedSpace}. The resulting wavelengths plotted in this space are shown on the CIE diagram of figure \ref{Fig:CIEDiagram}. All visible colours can be defined in this way, though only their normalised values are shown on colour prints of the diagram.
	
The pure visible colours are distributed on the edge of the horseshoe shaped curve with their physical wavelength running from 380 to 780 nm. At top and bottom ends of the visible spectrum, where the cell responses fall off, the wavelengths converge very fast towards a vanishing point. For example the wavelength 700 nm is virtually coincident with the 780 nm point in figure \ref{Fig:CIEDiagram}.  We can see that just below 500 nm the red component is zero and the blue and green are approximately equal which would correspond to the colour cyan.  The straight line from 780 to 540 on the right hand side represents the condition that $x+y=1$ which means that the blue component is zero.  The straight line at the bottom, joining 380 to 780 is a combination of red and blue, which has no equivalent single wavelength colour. It is called the magenta line. All visible colours are contained within the horseshoe, which must be convex, since all colours are a mixture of pure wavelengths. The usefulness of this diagram is that it expresses a linear additive system and the addition of colour components can be done graphically.

\subsection*{Graphical Manipulation of Colour Parameters}
\begin{wrapfigure}{r}{70mm}
  \vspace{-10mm}
  \begin{center}
     \includegraphics[width=70mm]{Figures/GraphicsColourCIECalculations.jpg} 
  \end{center}
  \vspace{-8mm}
  \caption{Calculations on the CIE Diagram}
   \vspace{5mm}
  \label{Fig:CIECalculations}
\end{wrapfigure}
Some definitions are shown on the CIE diagram of figure \ref{Fig:CIECalculations}. The white point, $x=y=z=1/3$, has equal strength of all three basic components.  Pure colours, around the edge of the horseshoe, are called pure or fully saturated colours.  If we take a pure colour, say 488 nm on the diagram, the line connecting this point and the white point contains all the possible colours which can be achieved by adding white to this pure colour.  If we extend this line and on the other side it hits the curve at another pure colour point (598 nm in this case), which is called the complement because mixing the two makes white.
	
Saturation, or the degree of purity, of a given colour point can also be determined graphically. The white point is completely unsaturated (has no colour).  The ratio of distances between the colour and the white point and the pure colour and the white point gives us saturation:
\begin{equation}
\nonumber
 saturation =  \frac{ |W-U| }{ |W-P|}
\end{equation}
The saturation is always taken as 1 on the horseshoe (fully saturated) and zero at the white point. If we take any colour on the diagram, for example [0.2, 0.3, 0.5] shown in figure \ref{Fig:CIECalculations}, we can measure this ratio, which in this case is approximately equal to 0.4.  This tells us the white content of the point. We can also determine a pure colour by considering the line through the point and the white point. From the slope of the line we can calculate that it cuts the y axis at [0, 0.25, 0.75].  This point is not in the visible region of the CIE diagram. The nearest pure colour will be seen to be around [0.04, .26, .736]. The complement of this colour can be found by determining the colour which when added to it will produce white. This will be on the z=0 line, so the blue component is zero, and so we have that [0.04, .26, 0.736] + [r,g,0] = [k,k,k] from the blue component we can find that k = .736, whence 0.04 + r = 0.736, so r = 0.696 and g = 0.476. If we normalise these points we get [0.6, 0.4, 0.0] as shown on the diagram. Notice that the normalisation on the diagram gives a weighting to the colour coordinates. Since on the diagram the line joining a colour and its complement always goes through the white point, it is always possible to find a linear combination of the two that produces white. It does not mean that adding the co-ordinates and normalising produces white.

\subsection*{Subtractive Colour representation}
\begin{wrapfigure}{r}{35mm}
  \vspace{-25mm}
  \begin{center}
     \includegraphics[width=35mm]{Figures/GraphicsColourPrimaryColours.jpg} 
  \end{center}
  \vspace{-8mm}
  \caption{The Primary Colours}
  \vspace{-4mm}
  \label{Fig:PrimaryColours}
\end{wrapfigure}
Paints and printing ink absorb colour reflecting only part of the incident light. For this reason they are called subtractive primaries The three principal colours of paints are magenta (purple), cyan (pale blue) and yellow.  These three can be created by combining the additive colour primaries. Magenta is red and blue, cyan is blue and green, and yellow is red and green.  Black is created by a blend of the three subtractive primaries, but is usually also used in colour printing for convenience. It reflects none of the incident light. White paint (or paper) reflects all the incident light and so does not change its colour.  Black and white paints can be blended to produce different shades of grey.  With grey and red paint you may make brown, and a milliard other colours which have no equivalents in the preceding systems.  Paints are much richer than colours produced by red/green/blue lights.
	
Figure \ref{Fig:PrimaryColours} indicates how the different, pure basic colours are generated by the additive (monitor) and subtractive (printer) colour systems.  Each circle represents one basic additive (R,G,B), or subtractive (M,C,Y) colour.  The other regions indicate pure colours generated by two basic colour addition or subtraction, respectively.  The centre colour (three addition or subtraction) in the additive system is white, while it is black in the subtractive system (all colours are absorbed).  The two systems show additive or subtractive complementary colours in the same region; i.e., red + cyan light makes white while red + cyan paint makes black.

\subsection*{Practical Colours}

Approximately 128 different hues may be distinguished by the human eye. For each hue around 20 to 30 different saturation values may be seen as different colours. The eye is capable of distinguishing between 60 and 100 different brightness levels. If we multiply these three numbers, we get approximately 350,000 different colours.  24 bits provides us over 1.6 million colour shades, however, the eye is very sensitive to differences and under some circumstances small differences can be detected by it.

When a transformation is necessary from the CIE standard colour chart to the colour produced on a specific display device, we must express the primary colours of the display device by x and y quantities. Good quality monitors will be calibrated for the CIE colour chart.  For example, a colour monitor may have the following primary colour sources:
\newline
\begin{tabular}{l c c c}
  &x &y &z \\
Red & 0.628 & 0.346 &0.026 \\
Green & 0.268 & 0.588 & 0.144 \\
Blue & 0.150 &0.07 & 0.780
\end{tabular}
\newline
These three points define a triangle on the CIE chromaticity diagram, as shown in figure \ref{Fig:DisplayColours}. Only the points inside this triangle may be reproduced by the display device. 

\subsection*{Colour Spaces and Transformation of Colours}
\begin{wrapfigure}{r}{70mm}
  \vspace{-10mm}
  \begin{center}
     \includegraphics[width=70mm]{Figures/GraphicsColourDisplayColours.jpg} 
  \end{center}
  \caption{Display Colours}
  \vspace{5mm}
  \label{Fig:DisplayColours}
\end{wrapfigure}
There are many different ways of representing colour, and often they can be expressed as linear combinations of each other. For example, the transformation from computer colour intensities R,G,B (expressed in the range from 0.0 to 1.0) may be done by the matrix:
\begin{equation}
  [x,y,z] =  
 \left[
  \begin{array}{ c c c  }
     0.628 & 0.268 & 0.150\\
     0.346 & 0.588 & 0.07 \\
     0.026 & 0.144 & 0.780 
  \end{array} \right] 
 \left[
  \begin{array}{ c }
     R \\
     G \\
     B
  \end{array} \right] 
\end{equation}
The pure red on the monitor has representation of [1.0, 0, 0] which then produces the correct CIE values of [0.628, 0.346, 0.026] for the monitor.  In order to find out how to represent a known CIE colour on the display, we have to invert the matrix and then right multiply it with the vector [x,y,z].

One useful colour space is called the HSV (Hue, Saturation and Value) space. It is of interest since it is thought to correspond more closely to our perception of colour than the RGB space we have been discussing.  Like the RGB system, a colour is represented by three values which can be calculated from the r g b values as follows:
\newline
\begin{tabular}{l}
$V = max(r,g,b)$ \\
$S = ( max(r,g,b) - min(r,g,b) ) / max(r,g,b)$
\end{tabular}
\newline
Hue (which is an angle between $0$ and $360^o$) is best described procedurally:
\newline
\begin{tabular}{l l}
if $(r=g=b)$         & Hue is undefined, the colour is black, white or grey. \\
if $(r>b)$ and $(g>b)$ & Hue $= 120*(g-b)/((r-b)+(g-b))$ \\
if $(g>r)$ and $(b>r)$ & Hue $= 120 + 120*(b-r)/((g-r)+(b-r))$ \\
if $(r>g)$ and $(b>g)$ & Hue$ = 240 + 120*(r-g)/((r-g)+(b-g))$
\end{tabular}
\newline
There are other, very similar, perceptual colour space called HSL (lightness) and HSI (intensity) which have slightly different definitions for saturation and intensity.
Note that, every colour in the RGB system is made up of a white component whose magnitude is the minimum out of r g and b, and a pure colour defined by the ratio of the two non-zero colours when the white component has been subtracted (Figure \ref{Fig:TriStimulusColour}). Note that the pure colour is not a coherent wavelength as in the CIE diagram. The saturation is the proportion of pure colour. As in the RGB system colours may be adjusted by changing any of the three values. However, with the HSI system the three variables each correspond to properties of colour we can easily understand, and thus they are easier to use to adjust colour palettes and balance colour images.

\subsection*{Alpha Channels}
\begin{wrapfigure}{r}{70mm}
  \vspace{-10mm}
  \begin{center}
     \includegraphics[width=70mm]{Figures/GraphicsColourTriStimulusColour.jpg} 
  \end{center}
  \vspace{-8mm}
  \caption{A tri-Stimulus Colour}
   \vspace{5mm}
  \label{Fig:TriStimulusColour}
\end{wrapfigure}
Colour representations in computer systems sometimes use four components to represent each colour. The first three are R G and B and the fourth or alpha value is simply an attenuation of the intensity. This does not add anything further to the representation, but allows greater flexibility in representing colours and can avoid truncation errors at low intensities. It can also be used for providing special features such as masking certain parts of an image.

\end{document}