Colour

1 Shan He 2013 What is light?

'White' light is a combination of many different light wavelengths

2 Shan He 2013 Colour spectrum – visible light

• Colour is how we perceive variation in the energy (oscillation wavelength) of visible light waves/particles.

Ultraviolet Infrared

400 nm Wavelength 700 nm • Our eye perceives lower energy light (longer wavelength) as so-called red; and higher (shorter wavelength) as so-called blue • Our eyes are more sensitive to light (i.e. see it with more intensity) in some frequencies than in others 3 Shan He 2013 Colour perception

. It seems that colour is our brain's perception of the relative levels of stimulation of the three types of cone cells within the human eye . Each type of cone cell is generally sensitive to the red, blue and green regions of the light spectrum

Images of living human retina with different cones sensitive to different colours.

4 Shan He 2013 Colour perception

. Spectral sensitivity of the cone cells overlap somewhat, so one wavelength of light will likely stimulate all three cells to some extent . So by mixing multiple components pure light (i.e. of a fixed spectrum) and altering intensity of the mixed components, we can vary the overall colour that is perceived by the brain.

5 Shan He 2013 Colour perception: Eye of Brain?

• Stroop effect

6 Shan He 2013 Do you see same colours I see?

• The number of color-sensitive cones in the human retina differs dramatically among people

• Language might affect the way we perceive colour

7 Shan He 2013 Colour spaces

. A colour space represents a system for accurately describing colours by some well defined parameters (e.g. some mixture of varying intensities of well-defined primary colours).

. Most colours can be represented using three colour components - but not all!

. They are called the primary colours (or the primaries)

8 Shan He 2013 Colour spaces

. There are many colour spaces. . The choice of a particular space depends on the context in which we wish to describe colours. . The four most common colour spaces are: • RGB: additive colour space • HSV: artistic colour space • CMY: subtractive colour space • XYZ: based on human colour perception . Others include: YIQ, YUV, YdbDr, YcbCr, xvYCC

9 Shan He 2013 RGB

. Primaries: Red - Green - Blue – Note that even with the general RGB space there may be slight variations in the choice of primaries . Primaries are similar to the colour sensitivities of receptors (cone cells) in the eye . Used in TV and computer display technology . We can visualise the RGB colour space as a 3D space with axis for the intensity of red, green, and blue. Blue Cyan

White Magenta

Black

Red Yellow 10 Shan He 2013 RGB

• RGB space rendered as an opaque cube. • Note that within the cube are infinite combinations of the three primaries • Though our eyes will not be sensitive to all of these subtle variations.

11 Shan He 2013 RGB – an additive system

12 Shan He 2013 HSV

. Primaries: Hue - Saturation - Value . Colour space is parametrised to be more useful to artists and designers, who are usually interested in the hue (mixture of primary colours) primarily, then they may vary the value (i.e. overall brightness) and saturation (strength of primary colours in the mix) . This is simply another geometry for expressing that of RGB . Sometimes called HSB. B (Brightness)

13 Shan He 2013 HSV

14 Shan He 2013 HSV

15 Shan He 2013 CMY

. Primaries: Cyan - Magenta – Yellow

. Used in printing technology . Mixing is subtractive

16 Shan He 2013 CMY – subtractive system

17 Shan He 2013 CIE XYZ

. Primaries: X, Y, Z . Based on colour perception of humans (derived from colour matching experiments), so it tries to evenly distribute perceived colour changes over the space . Device independent (i.e. not specifically designed for printing or displays) . The most common representation of the CIE XYZ space is the CIE chromaticity diagram, which is a 2D projection of its cross section

18 Shan He 2013 CIE XYZ Chromacity diagram

• Triangle represents a sub-space of the CIE which has red,green, and blue primaries (i.e. an RGB space) • CIE XYZ designed so all visible colours within a polygon can be mixed from the primary colours - hence strange shape • CIE XYZ can describe all visible colours, though our monitor (being RGB) cannot display those

19 Shan He 2013 Vector notation for colours

[ Primary1 Primary2 Primary 3 ]

[ R G B ] yellow = [ 1 1 0 ] orange = [ 1 0.5 0 ] Pink = [ 1 0.7 0.7 ]

[ H S V ] pink = [ 0 0.3 1 ]

[ C M Y ] red = [ 0 1 1 ]

20 Shan He 2013 Colour space conversion

. Colours can be converted from one space to another

. Conversion from RGB to CMY: [ C M Y ] = [ 1 1 1 ] - [ R G B ]

. Example: Convert green from RGB to CMY [ C M Y ] = [ 1 1 1 ] - [ 0 1 0 ] = [ 1 0 1 ]

21 Shan He 2013 Conversion from RGB to XYZ

. Each of the R, G and B primaries is a weighted sum of X, Y and Z primaries . Approx. Weights expressed in matrix notation . Conversion implemented as a matrix multiplication

0.41 0.21 0.02 [ R G B ] = [ X Y Z ] · 0.36 0.72 0.12 0.18 0.07 0.95

22 Shan He 2013 Conversion from RGB to XYZ

. And for the reverse conversion...

0.584 0.311 0.047 [ X Y Z ] = [ R G B ] · 0.188 0.614 0.103 0.179 0.075 0.939

23 Shan He 2013 Colour Spaces in Java

. Colour Spaces and Colours are implemented in the java.awt.color.* package . Abstract class ColorSpaces provides as constants • a number of standard colour spaces: CS_CIEXYZ, CS_sRGB • some specific colour space types: TYPE_HSV, TYPE_RGB, TYPE_CMY, TYPE_XYZ • some generic colour space types wrt. different number of components . One can obtain an instance of a colour space using the getInstance(int colorspace) method. For example: ColorSpace.getInstance(ColorSpace.CS_sRGB); returns a standard RGB colour space.

24 Shan He 2013 Colour Space Conversion in Java

. It is often necessary to convert between colour spaces of different images. The ColorSpace class provides some simple methods to do this: • toRGB(float[ ] colorvalue): Transform colour value from the space to standard RGB • fromRGB(float[ ] rgbvalue): Transform colour value from RGB to the this space • toCIEXYZ(float[ ] colorvalue): Transform colour value from the space to CIEXYZ • fromCIEXYZ(float[ ] colorvalue): Transform colour value from CIEXYZ to this space

25 Shan He 2013 Colours in Java

. Colours (e.g., for the Paint component) can be defined wrt. any colour space with constructor: Color(ColorSpace cspace, float[] components, float alpha) . More easily the can be defined via RGB values

Color(float r, float g, float b) . Java also provides some default colours in the RGB model: • Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW, Color.BLACK, Color.WHITE, Color.CYAN, etc.

26 Shan He 2013