Thursday, April 16, 2009

Spatial representations of colour spaces

The RGB and HSB colour spaces have natural representations as
threedimensional
shapes (‘threedimensional’
because there are
three components needed to specify a colour). The RGB space is
13
CC227 Creative Computing II Perception and Information Retrieval
most clearly represented as a colour cube: each of the red, green
and blue components of the colour space corresponds to one of the
axis directions of the threedimensional
space, and so a particular
colour’s position in this space is specified by a particular amount of
red, green and blue. Given this representation, it is possible to
express the colour distance between two colours, corresponding to
the distance between points in this colour space; for colours C and
C�, if ∆r = r − r� (and similarly for the green and blue components)
then the difference in colours is
∆CRGB = �(∆r)2 + (∆g)2 + (∆b)2. (1.6)
For this to be meaningful, the range of r, g, b (e.g. [0, 1) or [0, 255])
needs to be specified.
h
b s
Figure 1.4: The HSB colour space represented as a cone; the directions
of hue, saturation and brightness are shown as h, s and b.
The HSB space is most easily represented as a cone: the hue
coordinate is arranged in a circle; the saturation of a colour
increases towards the outside of the cone; and the brightness varies
along the cone’s axis (see figure 1.4. This means that a colour
position can be represented in coordinates as {b, bs cos h, bs sin h},
which means that in this space
∆CHSB = �(∆b)2 + (bs cos h − b�s� cos h�)2 + (bs sin h − b�s� sin h�)2
(1.7)
We will discuss the distances between colours more in section 1.3.4;
for now, be aware that the distances expressed in equations 1.6 and
1.7 are neither equal to each other nor strongly related to the
perception of colour differences. Both of these spaces are useful for
computational manipulation, but they do not capture the complexity
of relationships between colours.
Learning activity
Using the builtin
support for the RGB and HSB colour spaces in Processing, construct
3D sketches illustrating the cube and cone representations discussed in this section.
Afterimages and John Sadowski’s illusion
After staring at an image for a while, looking at a plain white
surface gives the perception of a ‘negative’ version of the stimulus
14
Colour Spaces and Profiles
(where dark regions in the negative correspond to light ones in the
original, and vice versa). This is known as a negative afterimage, and
occurs because the cone cells in the retina lose their sensitivity
temporarily after being overstimulated. When the attention is
turned to a white surface after looking at the image, those cells that
previously were firing will be less responsive, while those that were
not will respond as normal (and hence will fire more).
Learning activity
Processing has support for inverting an image in the HSB colour space, using the
INVERT specification to PImage.filter(). The following code implements an
illusion due to John Sadowski: staring at an inverted image, then at a greyscale version
of the original, gives the perception of the full colour image, until the eye moves.
PImage orig, gray, invert;
boolean inverted = false;
void setup() {
orig = loadImage("/home/crhodes/tmp/foo.jpg");
size(orig.width,orig.height);
gray = new PImage(orig.width,orig.height);
gray.copy(orig,0,0,orig.width,orig.height,0,0,orig.width,orig.height);
gray.filter(GRAY);
invert = new PImage(orig.width,orig.height);
invert.copy(orig,0,0,orig.width,orig.height,0,0,orig.width,orig.height);
invert.filter(INVERT);
colorMode(HSB);
invert.loadPixels();
for (int i = 0; i < invert.pixels.length; i++) {
float h = hue(invert.pixels[i]);
float s = saturation(invert.pixels[i]);
float b = brightness(invert.pixels[i]);
invert.pixels[i] = color(h, (s+255+255)/3, (b+255)/2);
}
}
void keyPressed() {
inverted = !inverted;
}
void draw() {
image(inverted ? invert : gray,0,0);
fill(0);
ellipse(orig.width/2,orig.height/2,2,2);
}
The INVERT filter inverts the hue in HSB space, whereas the opponent process
theory of colour vision would suggest that Sadowski’s illusion should be stronger if red
is transformed to green and yellow to blue. Investigate which version is more effective
for you.

No comments:

Post a Comment