# [GRASSLIST:3173] Re: r.composite and the -c flag

Glynn Clements glynn.clements at virgin.net
Wed Apr 14 23:17:49 EDT 2004

```Magnus Rohde wrote:

> What does the -c flag in r.composite do? The html man-page (from 5.3)
> only says "use closest colour", but what does that mean?

It changes the way in which a 0-255 intensity value is converted to an
intensity level. Without -c, the calculation is:

l = v * levels / 256

With -c it is:

l = (v + 128 / (levels - 1)) * (levels - 1) / 256

E.g. for levels=4, the assignment is:

l	v (without -c)	v (with -c)

0	  0 -  63	  0 -  43
1	 64 - 127	 44 - 128
2	128 - 191	129 - 213
3	192 - 255	214 - 255

Note that the colours in the colour table are always given by:

v = i * 255 / (levels - 1)

so the bottom band is always zero intensity and the top band is always
maximum intensity (255).

With -c, each band is centred on its representative intensity level,
so the first and last bands are centred on 0 and 255 respectively, and
so half of each of those bands is unused (you can't have values below
0 or above 255).

Using -c results in a slight increase in accuracy; omitting it results
in a more even distribution of intensity levels.

There is a third alternative, which would provide both accuracy and an
even distribution, i.e. to partition the 0-255 range as is done
without -c, but set the colour table to use the centre of each band,
so that the lowest band is not quite zero intensity and the highest
band is not quite maximum intensity. r.composite doesn't support this
option directly, but you could use r.composite without -c then change
the colour table with "r.colors ... color=rules" and a script.

--
Glynn Clements <glynn.clements at virgin.net>

```