10
Software System Components B – Graphics Shan He LECTURE 6 Colour 1.1. Outline of Lecture Review of what we learned Some concepts about colour Colour space Colour space in Java 1.2. Review of what we learned 1.3. Some concepts about colour Before diving into our lecture, our first question is: what is colour? In 1666, by allowing white light passes through a prism, Sir Isaac Newton discovered that pure white light is a combination of many different colours. Newton also found that each color is made up of a single wavelength and cannot be separated any further into other colors. After several hundred years’ research here is a more precise but very physical definition of light: it is “a name for a range of electromagnetic radiation that can be detected by the human eye”. So what is “electromagnetic radiation”? Electromagnetic radiation is a form of energy behaves as waves when it travels through space. Here is a less technical definition: colour is how we perceive variation in the energy (oscillation wavelength) of visible light waves/particles. 1

Software System Components B { Graphics · 2013-01-16 · LECTURE 6. COLOUR 7 Figure 7. HSV space visualisation in 3D. usually white background will be partially or entirely masked

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Software System Components B { Graphics · 2013-01-16 · LECTURE 6. COLOUR 7 Figure 7. HSV space visualisation in 3D. usually white background will be partially or entirely masked

Software SystemComponents B – Graphics

Shan He

LECTURE 6Colour

1.1. Outline of Lecture

• Review of what we learned• Some concepts about colour• Colour space• Colour space in Java

1.2. Review of what we learned

1.3. Some concepts about colour

Before diving into our lecture, our first question is: what is colour? In1666, by allowing white light passes through a prism, Sir Isaac Newtondiscovered that pure white light is a combination of many differentcolours. Newton also found that each color is made up of a singlewavelength and cannot be separated any further into other colors. Afterseveral hundred years’ research here is a more precise but very physicaldefinition of light: it is “a name for a range of electromagnetic radiationthat can be detected by the human eye”. So what is “electromagneticradiation”? Electromagnetic radiation is a form of energy behaves aswaves when it travels through space. Here is a less technical definition:colour is how we perceive variation in the energy (oscillationwavelength) of visible light waves/particles.

1

Page 2: Software System Components B { Graphics · 2013-01-16 · LECTURE 6. COLOUR 7 Figure 7. HSV space visualisation in 3D. usually white background will be partially or entirely masked

2 SHAN HE, SOFTWARE SYSTEM COMPONENTS B – GRAPHICS

As we can see from Figure 9, our eye perceives lower energy light(longer wavelength) as so-called red; and higher (shorter wavelength)as so-called blue. In fact, our eyes are more sensitive to light (i.e. seeit with more intensity) in some frequencies than in others.

Figure 1. Colour and wavelength

In fact, the study of physical property of colour and the technologiesof using colour, e.g., textile dyeing, is called colour science, which is avery established area. For example, the Department of Colour Scienceat Leeds University was founded in 1878. However, the phycologicaldefinition is still not clear and there are a lot of unsolved questionsabout how we perceive colour. The study of colour in phycology is anemerging field, called colour phycology.

Here we only introduce some concepts about our perception ofcolour in colour phycology. Our Brain can perceive the relative lev-els of stimulation of the three types of color receptors, or cone cellswithin the human eye. Each type of cone cell is generally sensitive tothe red, blue and green regions of the light spectrum.

No

rma

lise

d c

on

e r

esp

on

se

Figure 2. Normalized response spectra of human cones, short(S), medium (M), and long (L) cone types, to monochromatic spec-tral stimuli, with wavelength given in nanometers.

Page 3: Software System Components B { Graphics · 2013-01-16 · LECTURE 6. COLOUR 7 Figure 7. HSV space visualisation in 3D. usually white background will be partially or entirely masked

LECTURE 6. COLOUR 3

In practice the spectral sensitivity of the cone cells overlap some-what, so one wavelength of light will likely stimulate all three cells tosome extent. So by mixing multiple components pure light (i.e. of afixed spectrum) and altering intensity of the mixed components, wecan vary the overall colour that is perceived by the brain. You couldprobably say very similar things about our sense of smell, for example.

Figure 3. Images of living human retinas showing the wide diver-sity of number of cones sensitive to different colors. (Photo credit:University of Rochester)

In 2005, ”Researchers at the University of Rochester have foundthat the number of color-sensitive cones in the human retina differsdramatically among people, - by up to 40 times. yet people appear toperceive colors the same way.” See Figure 2 for images of living conecells. (If you are interested about their research, you can read thisarticle: It’s In The Brain: Color Perception Is Not In The Eye Of TheBeholder, or you can see BBC iPlayer here ). Such results stronglysuggest that our perception of color is controlled much more by ourbrains than by our eyes.

Here is another proof of the perception of colour is mainly controlledby our brain: the Stroop effect. Please look at Figure 4, try to namethe colours of the words, try not to be disturbed by the word.

However, do you see the same colours that I see? The answer isNO. Many factors influence the way we perceive colour, one of themis language. One interesting question is, could the number of wordsto describe colour affect the way we perceive it? The only way to findout was to go to a tribe, the Himba in northern Namibia, who haveonly four words for colour: Zuzu stands for dark shades of blue, red,green and purple; Vapa is white and some shades of yellow; Buru issome shades of green and blue; and Dambu is some other shades ofgreen, red and brown. It was interesting to find that, Himba call thesky Zuzu (black) and water Vapa (white), and for them, blue and greenshare the same word Buru. One strong evidence is that it takes themlonger to differentiate between certain colours, e.g., blue and black. It

Page 4: Software System Components B { Graphics · 2013-01-16 · LECTURE 6. COLOUR 7 Figure 7. HSV space visualisation in 3D. usually white background will be partially or entirely masked

4 SHAN HE, SOFTWARE SYSTEM COMPONENTS B – GRAPHICS

BLUE GREEN YELLOW

PINK RED ORANGE

GREY BLACK PURPLE

TAN WHITE BROWN

Figure 4. The Stroop effect

was very difficult for them to distinguish green and blue because thesetwo colour share the same word. But they can differentiate easily andimmediately between close shades of color that they categorize underdifferent names. For example, red and yellow. It seems that, becausethey have few words for colour than us, their perception of the colouris a little different to ours. You might take a look at this video fromBoreme.com (Information from BBC Horizon: Do You See What ISee?). However, it is entirely possible that such phenomenon has agenetic basis, e.g, they are all colour blind to some colours.

1.4. Colour spaces

A wide range of colors, not all, can be created by the primary colors ofpigment. They are called the primary colours (or the primaries). Notethat these primary colours are often relate to physiological response ofthe eye to light rather than the a fundamental property of light. Theseprimary colours define a colour space. There are many different colourspaces:

• Read Green Blue (RGB): additive colour space• Hue Saturation Value (HSV): artistic colour space• Cyan Magenta Yellow (CMY): substractive colour space• XYZ: based on human colour perception• Others: YIQ, YUV, YdbDr, YcbCr, xvYCC

Page 5: Software System Components B { Graphics · 2013-01-16 · LECTURE 6. COLOUR 7 Figure 7. HSV space visualisation in 3D. usually white background will be partially or entirely masked

LECTURE 6. COLOUR 5

The choice of a particular space depends on the context in whichwe wish to describe colours. In the following subsections, we will lookat RGB, HSV, CMY and XYZ.

1.4.1. RGB colour space

Read Green Blue (RGB) is one of the most popular colour space sys-tems, which has been widely used in TV and other computer and videodisplays. The primaries, i.e., read green and blue are similar to thecolour sensitives of receptors (cone cell) in the eye. As shown in Figure5, we can visualise the RGB colour space as a 3D cube with axis forthe intensity of red, green and blue.

Blue Cyan

Magenta

Red Yellow

GreenBlack

White

Figure 5. RGB colour space visualisation in 3D.

As we can see in Figure 6, RGB space is rendered as an opaque cube,within the cube, there are infinite combinations of the three primaries,though our eyes are not sensitive to all of these subtle variations.

Here is a cool interactive Java 3D colour cubes by NostradamusAdvertising: click here)

Or this CSS version: click here)One property distinguishes RGB colour space with other colour

spaces is that it is an additive system, that is, the system combinesemitted lights from primaries to create the sensation of a range ofcolors.

Page 6: Software System Components B { Graphics · 2013-01-16 · LECTURE 6. COLOUR 7 Figure 7. HSV space visualisation in 3D. usually white background will be partially or entirely masked

6 SHAN HE, SOFTWARE SYSTEM COMPONENTS B – GRAPHICS

Figure 6. Rendered RGB colour space as an opaque cube.

1.4.2. HSV colour space

HSV (Hue Saturation Value) colour space is also know HSB (Hue, Satu-ration, Brightness). This space is often used by artists because they areusually interested in Hue (represents mixture of primary colours), thenthey may vary the Saturation (represents purity of colour, or strengthof primary colour in the mix) and the Value (represents overall bright-ness of the colour). HSV system more natural to artists than additivesystems, e.g., the RGB colour system. We can visualise HSV colourspace using a 3D cylinder as shown in 7. The rendered HSV colourspace is shown in 8.

HSV is simply a transformation of an RGB colour. I will not gointo details of the transformation, but if you are interested, you canread this web page).

1.4.3. CMY colour space

CMY (Cyan, Magenta and Yellow) colour space is a subtractive system,which has been widely used in color printing technology. CMY systemrefers to the four inks used in some color printing: cyan, magenta, yel-low, and key (black). Therefore, it is also know CMYK colour space. Khere stands for Key. By applying the four primaries, the background,

Page 7: Software System Components B { Graphics · 2013-01-16 · LECTURE 6. COLOUR 7 Figure 7. HSV space visualisation in 3D. usually white background will be partially or entirely masked

LECTURE 6. COLOUR 7

Figure 7. HSV space visualisation in 3D.

usually white background will be partially or entirely masked to re-duce the light reflected from the background. Such a model is calledsubtractive because the primaries ”subtract” brightness from white.

1.4.4. XYZ colour space

CIE XYZ color space is also known as CIE 1931 color space, whichwas created by the International Commission on Illumination in 1931.It has three primaries: X, Y, Z. It is based on colour perception ofhumans (derived from a series of colour matching experiments done inthe late 1920s), so it tries to evenly distribute perceived colour changesover the space. It is device independent (i.e. not specifically designedfor printing or displays). The most common representation of the CIEXYZ space is the CIE chromacity diagram, which is a 2D projection ofits cross section.

Triangle represents a sub-space of the CIE which has red,green, andblue primaries (i.e. an RGB space). CIE XYZ designed so all colourswithin a polygon can be mixed from the primary colours at its vertices -hence strange shape. Hence, RGB cannot describe all visible colours, ascan CIE XYZ, though sadly out monitor (being RGB) cannot displaythose. It suffices for us to know that many standardised colour spacesfor printing, displays, and cameras are derived from this space to ensurethat colours can be matched from one device to another.

Page 8: Software System Components B { Graphics · 2013-01-16 · LECTURE 6. COLOUR 7 Figure 7. HSV space visualisation in 3D. usually white background will be partially or entirely masked

8 SHAN HE, SOFTWARE SYSTEM COMPONENTS B – GRAPHICS

Hue

Value

Saturation

Figure 8. Rendered HSV colour space as a opaque cylinder.

1.4.5. Conversion between difference colour spaces

We can represent a specific colour using a vector: [Primary1 Primary2Primary3 ]. For example, in RGB colour space:

yellow = [ 1 1 0 ] orange = [ 1 0.5 0 ] pink = [ 1 0.7 0.7]Using the vector representation, we can use some equations for con-

version between difference colour spaces:Convert RGB to CMY:[C M Y ] = [1 1 1] - [R G B]For example, we can convert green from RGB to CMY.[C M Y] = [1 1 1] - [0 1 0 ] = [1 0 1]Convert RGB to XYZ: Each of the R, G and B primaries is

a weighted sum of X, Y and Z primaries. Approximated Weights ex-pressed in matrix notation, Conversion between these two spaces areimplemented as a matrix multiplication. For example:

[R G B] = [X Y Z] ·

0.41 0.21 0.020.36 0.72 0.120.18 0.07 0.95

Page 9: Software System Components B { Graphics · 2013-01-16 · LECTURE 6. COLOUR 7 Figure 7. HSV space visualisation in 3D. usually white background will be partially or entirely masked

LECTURE 6. COLOUR 9

Figure 9. Images of living human retinas showing the wide diver-sity of number of cones sensitive to different colors. (Photo credit:University of Rochester)

Convert XYZ to RGB: Similar to above:

[X Y Z] = [R G B] ·

0.584 0.311 0.0470.188 0.614 0.1030.179 0.075 0.939

An excellent Java applet demonstration of the relationships between

different colour space can be found at:http://dcssrv1.oit.uci.edu/ wiedeman/cspace/).

1.5. Colour Spaces in Java

Colour Spaces and Colours are implemented in the java.awt.color.*

package. Abstract class ColorSpaces provides as constants a numberof standard colour spaces: CS CIEXYZ, CS sRGB. There are somespecific colour space types: TYPE HSV, TYPE RGB, TYPE CMY,

Page 10: Software System Components B { Graphics · 2013-01-16 · LECTURE 6. COLOUR 7 Figure 7. HSV space visualisation in 3D. usually white background will be partially or entirely masked

10 SHAN HE, SOFTWARE SYSTEM COMPONENTS B – GRAPHICS

TYPE XYZ. One can obtain an instance of a colour space using thegetInstance(int colorspace) method. For example:

ColorSpace.getInstance(ColorSpace.CS_sRGB);

, which returns a standard RGB colour space.It is often necessary to convert between colour spaces of different

images. The ColorSpace class provides some simple methods to do this:

• Transform colour value from the space to standard RGB:

toRGB(float[ ] colorvalue)

• Transform colour value from RGB to the this space:

fromRGB(float[ ] rgbvalue)

• Transform colour value from the space to CIEXYZ:

toCIEXYZ(float[ ] colorvalue)

• Transform colour value from CIEXYZ to this space:

fromCIEXYZ(float[ ] colorvalue)

Usually we can define colour 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.