2. Colour Mixing

In this section, I would like to briefly discuss how the three narrow-band colour channels (R, G, B) are used to mimic the continuous colour spectrum of the sky throughout the day.

Short introduction to the physics of colour

There exist different ways of expressing colours. The most fundamental physical quantity related to colours is the frequency of light. It is often transformed to wavelength, which is the speed of light divided by the frequency λ = c/f. However, since most of us - humans - can only see the world through three colours: red, green and blue (also known as the `primary' colours), any colour that belongs to the visible spectrum (approximately 400 - 700 nm wavelength) can be "synthesised" by mixing of the primary colours in the right proportions. For example, our eyes will not be able to distinguish between the originally yellow colour from the proper mixture of red and green.

Colour can also be expressed in terms of temperature (K), although this definition is more subtle. Simply speaking, when a physical body is heated, it begins to radiate the energy. The spectrum of this energy is continuous, but it does possess a peak at a certain frequency. Now, the higher the temperature of the body, the further this peak is being shifted towards higher frequencies (from red to blue). The colour resulting from the particular spectrum became directly related to the temperature of the body, hence the concept colour temperature. It is important to add here, that the body is not just any object, but it is specifically related to a so-called "black body", which is a purely theoretical concept. Still, certain objects behave very much like black bodies including our Sun, which a good example.

Temperature to RGB transformation

The challenge is to represent the continuous spectrum of the sky. The colour of the sky originates from the sunlight and it is the effect of light being scattered by the atmosphere. It is still continuous in spectrum, but we need to have it represented by the three primary colours. There exist mathematical models, however for this application it is fine to use tabulated data.

Brightness correction

Although the data presented in provide the necessary link between the two representations, they do not take into the account that we use LEDs as light source. In fact, for LEDs the light intensity of each channel is rarely equal. The first source of this imbalance is the fact that RGB LEDs are usually formed by combining three individual single-coloured LEDs in one package. Since each of them has a different light conversion efficiency, they emit different optical power for the same electrical power. Furthermore, even if their optical powers were equal, our eyes are not equally sensitive to all colours.

Our perceptual response to light power(not relative to colours) is expressed in terms of luminescence. According to the datasheet provided by the RGB LED manufacturer, the maximum luminescence of the individual colours are 67.5 cd, 165 cd, 60 cd, for red, green and blue respectively. Hence, if all three channels are provided with the same electric current, the green colour appears as the brightest. Therefore, in order to reconstruct the colour of the sky, it is necessary to equalise channels in terms of luminescence. There are two ways to do it. It can either be done in hardware by applying an additional series resistance to each channel or it is possible to apply a correction factor in the software. I found it both easier and more efficient to correct for the colour in software.

Procedure for brightness correction

plot_ColorTemperature
Figure 3. Original (uncalibrated) RGB channels against the colour temperature and the 8-bit index. The vertial dashed line represents the 6700 K value point.

Figure 3. shows the relationship between the RGB channels and the colour temperature (assuming equal brightness). Note that since range is limited to an 8-bit value, there exists point when the brightness of one channel cannot be increased any more and the others have to drop in order to preserve the mutual proportions. This point corresponds to the instance, when light at some point will stop appearing orange and begin to seem more bluish. It will cross the point, where all three channels are nearly maximum, corresponding to light being almost purely white. According to the figure, this occurs at around 6700 K. In order to calibrate the channels, I tuned the channels to obtain this shade by reducing the duty cycle of green and blue channels, at the same time reading the value displayed in binary using the STK600.

Although this method of calibration does not produce absolutely accurate results, it is certainly sufficient for the application. What is more, in order to reduce the effects of the brain memory and perception, I tried to cross this point several times both ascending and descending the temperature, each time noting the binary value down. The new channel values served as a reference point:

\text{RGB}: \quad \vec{C} = [255, 254, 255]_\text{old} \to [255,205,223]_\text{new} = \vec{C}'

Then, each of the channels' values was decreased linearly by accounting for this difference.

x' = x - x(255 - \max{x'}), x = \text{R, G, B}

Next step was to "skew" the colour range. When looking at the figure 3. the colour shades are nearly equally distributed both left to and right from the 6700 K point. In fact, however, the more "interesting" time from the aesthetic point of view occurs during the sunrise and sunset. It is also when the colours are changing the fastest rate. During the rest of the day (or night) the blue colour is nearly a constant. Therefore, it seems useful from both aesthetic and practical point of view to shift the range such that the red part of the range could get more resolution, while sacrificing the resolution of the blue part. For this reason, we transform the domain (temperature) in order to apply the change. For this purpose, we use the so-called γ-correction. Although it is normally used to adjust the brightness, here we will use it for colour.

T' = \left(\frac{T}{\max\{T\}}\right)^\gamma \cdot \max\{T\}
plot_TemperatureShift
Figure 4. Transformation of the colour domain to increase the resolution of the red part.

Finally, when below 1000K the olour of the table is not defined. Therefore, I decieded to use this as an opportunity ti add few more colour shades that could represent the sky shortly after sunset or before the sunrise. For this reason, I added a weak blue component to obtain a purple-like shade, while the sky at night is defined as a very weak blue [0,0,1].

Fitting in the day cycle

The exact colour of the sky during the day depends on many factors. It is only possible to estimate the colour temperature based on one's perception. Here, I have chosen a very simple solution. The assumed sunrised is set to starts at 7 a.m. and it is followed by 3.5 hour sunrise period. During this period, the imitated colour temperature is increased linearly with time, reaching the maximum of 13600K at 11:30 a.m. For the next 6.5 hour the light is constantly lit at the maximum temperature value. At exactly 5 p.m. the reverse process occurs and the light is constantly decreasing the temperature reaching full darkness 3 at 8:30 p.m.

Since the colour table was shifted, the change in shade of the blue colour is practically not to be notices. The changes in red colour shades are more visible. However, since the colour is updated every minute or so, and the colours are similar, the changes are disturbing to human eye (nor apparently the fish).

plot_DayCycle
Figure 5. The light temperature during daytime.

left right