---
tags: Digital Image Processing
disqus: hackmd
---
# Part 14
## Color Image Processing
This can be divided into,
1. Full-colour processing
2. Pseudocolour processing
In a BW image, only the intensity of the light varies. However, for chromatic light, there is also the wavelength of the light according to the electromagnetic spectrum. The light is defined by three quantities as,
1. Radiance - Total amount of energy coming from the light source (watts(W))
2. Luminance - Amount of energy perceived by the observer (Lumens)
4. Brightness - Subjective measure
When we talk about colours, we talk about three primary colours,
1. Red (R)
2. Green (G)
3. Blue (B)
These are the colours chosen as they are perceived best by the cone cells in our eyes (65% perceive red, 33% perceive green and 2% perceive blue).
By mixing the primary colours, we get secondary colours,
1. Red + Blue = Magenta
2. Green + Blue = Cyan
3. Red + Green = Yellow
The secondary colours are the primary colours for pigments and printing, whereas the original primary colours are used in digital images.
For the perception of colours, the characteristics are brightness, hue and saturation.
1. Brightness - Chromatic notion of intensity.
2. Hue - Dominant wavelength in a mixture of colours.
3. Saturation - Indicates the purity of a particular colour (shade of a colour).
The last two give colour sensation or they give chromaticity of light, whereas brightness gives the sensation of intensity.
The amount of red, green and blue light composition is represented by tristimulus, shown as $(X,Y,Z)$. The color is specified by chromatic coefficients shown as,
\begin{equation}
x = \frac{X}{X + Y + Z},y = \frac{Y}{X + Y + Z},z = \frac{Z}{X + Y + Z}
\end{equation}

So, if we take two different points on this diagram and join them by a line, it represents the different colour combinations we can get by mixing the two points in different proportions. Similarly, with more points, we can get colours inside the polygon drawn.
If one of them is white, we get the different shades of colour of that point.
### Color Model
We need the model to specify a particular colour for different purposes.
1. RGB - Image display like a monitor
2. CMY/CMYK - Image printing
Both of these models are hardware-oriented.
Another model is,
3. HSI - Application-oriented or perception oriented.
The model used for digital images are,

The diagonal line indicates the grayscale line.
In the digital case, we normally use 8-bit quantized images. When each of these channels is quantized, we have a total of 24 bits or $2^{24}$ possible colour combinations. These combinations have been quantized further to given 216 possible colour combinations (known as safe RGB model).
The colorspaces RGB and CMY can be related as,
\begin{equation}
\begin{bmatrix}
C \\ M \\ y
\end{bmatrix} =
\begin{bmatrix}
1 \\ 1 \\ 1
\end{bmatrix} -
\begin{bmatrix}
R \\ G \\ B
\end{bmatrix}
\end{equation}
Another color $K$ that is black, gives us CMYK model, which is used for printing.
Whenever we interpret a colour, rather than considering the amount of each of the primary colours present, we look at the prominent colour. This is known as Hue (H). Saturation (S) is the shade of the colour or the amount of white present. (I) is the intensity. The first two parameters are used for chromaticity.
These original colorspaces can be represented as,

Whenever a vector is drawn from black to anywhere in the cube, the projection into the intensity line will give the intensity of the line at that point. As the point moves away from the diagonal, the saturation increases. Therefore, the length of the line joining the point as well as its projection onto the diagonal indicates the amount of saturation.

Finding Hue is slightly complicated.
Suppose this cube is rotated such that the white and black points coincide in the projected 2D hexagon as,

In this case, the reference has been considered as red. Therefore, the hue is actually the angle between the saturation and the reference line. So, for red, the hue is zero degrees.

Mathematically, they have been defined as,
\begin{equation}
H =
\begin{cases}
\theta, B \leq G \\ 360 - \theta, G < B
\end{cases}
\end{equation}
Where,
\begin{equation}
\theta = \cos^{-1}\bigg\{\frac{\frac{1}{2}[(R - G) + (R - B)]}{[(R - G)^2 + (R - B)(G - B)]^{\frac{1}{2}}}\bigg\}
\end{equation}
Saturation can be written as,
\begin{equation}
S = 1 - \frac{3}{(R + G + B)}[\min(R,G,B)]
\end{equation}
Intensity is,
\begin{equation}
I = \frac{1}{3}[R + G + B]
\end{equation}
The inverse transformation is done in three cases,
1. $\text{RG Region}(0^0 \leq H < 120^0)$
\begin{equation}
B = I(1 - S) \\ R = I\bigg[1 + \frac{S\cos{H}}{\cos{(60^0 - H)}}\bigg] \\ G = I - (R + B)
\end{equation}
2. $\text{GB Region}(120^0 \leq H < 240^0)$
\begin{equation}
R = I(1 - S) \\ G = I\bigg[1 + \frac{S\cos{H}}{\cos{(60^0 - H)}}\bigg] \\ B = I - (R + G)
\end{equation}
3. $\text{BG Region}(120^0 \leq H < 360^0)$
\begin{equation}
G = I(1 - S) \\ B = I\bigg[1 + \frac{S\cos{H}}{\cos{(60^0 - H)}}\bigg] \\ R = I - (G + B)
\end{equation}
## Color Image Processing
Types:
1. pseudocolour Processing (False Color Processing) - Processing on colours which are not real to the image. It assigns colours to different grey levels on different criteria.
2. Full-Color Processing
### Pseudo Color Processing

This is the three-dimensional representation of the intensity of the image. At $f(x,y) = l_i$ a plane is kept parallel to XY plane. On slicing, the graph is divided into two different parts.
Suppose there are $L$ levels of intensitites for the image $(0,1,...,L - 1)$. $l_0$ represents black, that is, $f(x,y) = 0$. Similarly, $l_{L - 1}$ indicates white, that is, $f(x,y) = L - 1$.
Suppose there are $P$ planes perpendicular to the intensity axis. So, we have planes at $l_1, l_2, ..., l_p$, where $0 < p < L - 1$. With this, we have $p + 1$ intervals.
Define $h(x,y) = c_k$ if $f(x,y) \in V_k$ present between $(l_k, l_{k + 1})$. The intevals are $V_1, V_2, ..., V_{p + 1}$.
This concept is used quite frequently in level representations such as the number of intensities or severity of that particular pixel.
This can also be used for conversion of grayscale to colour image. So, we need three transformations: red, green and blue. So $f(x,y) \to f_R(x,y),f_G(x,y),f_B(x,y)$. So, giving grayscale different amount of weights, we can get three channels, which can be equated to a pseudo-coloured image.
### Full-Color Image Processing
An image can be represented in RGB or HSI colourspace. Different types of full-colour image processing are,
1. Per - colour image processing
2. Vectors
As vector, color at a point can be represented as,
\begin{equation}
c(x,y) =
\begin{bmatrix}
R(x,y) \\ G(x,y) \\ B(x,y)
\end{bmatrix}
\end{equation}
#### Color Transformations
The transformation was defined initially as $s = T(r)$. In case of color, this can be extended as $s_i = T(r_1,r_2,...,r_n), i = 1,2,...,n$. Every $r_i$ is a component of processed image of $f(x,y)$. $\{T_1,T_2,...,T_n\}$ are a set of transformations. In the cases discussed before, we had $n = 3$.
Some of its applications involve the use of intensity modification, where $g(x,y) = kf(x,y)$. $f$ is the input image and $g$ is the processed image. Here, $0 < k < 1$.
In case of RGB, we have $s_i = kr_i$, where $i = 1,2,3$. When we have HSI, only the intensity part will vary, so, $s_3 = kr_3,s_2 = r_2, s_1 = r_1$.
In CMY space we have $s_i = kr_i + (1 - k)$.
#### Color Complements

The complement of colour is diametrically opposite on the colour circle. Mathematically, it can be simply represented as $s_i = T(r_i) = L - 1 - r_i, i = 1,2,3$. This is similar to the photographic negative discussed before.
#### Color Slicing

A very simple form of color slicing example is,
\begin{equation}
S_i =
\begin{cases}
0.5, \big[|r_j - a_j| > \frac{W}{2}\big]_{1 \leq j \leq 3} \\ r_i, \text{ otherwise}
\end{cases}
i = 1,2,3
\end{equation}
So, colours outside the width are considered as some insignificant colour, but inside the cube, the original colour is maintained. This is good to extract information having a particular colour range such as colour segmentation. Note that it is not necessary to consider only a cube. It can also be a sphere.
#### Tone Correction
A colour image may have a flat, light or dark tone. This is represented by the distribution of intensity values in colour planes.

#### Smoothing
\begin{equation}
\hat{c}(x,y) = \frac{1}{k}\sum c(x,y), \forall x,y \in N_{x,y}
\end{equation}
Where $c$ is a vector having all three channels. So, whenever we perform the operations discussed before, per - color plane operations are performed, followed by combination to give the final output.