[GRASS-dev] problem with r.colors on Mac

Glynn Clements glynn at gclements.plus.com
Wed Apr 11 18:23:08 EDT 2007


Maciej Sieczka wrote:

> Messing around with the new feature I found there is a difference
> between -e/-g color=grey and the old color=grey.eq/grey.log; in spearfish:
> 
> $ r.colors landcover.30m col=grey.eq
> $ r.mapcalc 'tryit_old_eq=#landcover.30m'
> 
> $ r.colors -e landcover.30m col=grey
> $ r.mapcalc 'tryit_new_eq=#landcover.30m'
> 
> There is a difference between the 2 colortables it seems:
> 
> $ r.mapcalc 'dif_eq=tryit_new_eq-tryit_old_eq'
> $ r.info -r dif_eq
> min=-1
> max=0

grey.eq scales the fraction by 256 to get a grey level, while -e uses
it to interpolate the original colour table. If the original colour
table is a 0-255 grey scale, -e is effectively scaling the fraction by
255.

This comes down to how color_look.c (G_get_d_raster_color() etc)
interpolates colour rules. E.g. if you have a single grey-scale rule
with 0% = 0/0/0 and 100% = 255/255/255, 99.9999% gets you 254/254/254.

I don't think there's anything that I can do about this for -e. 
grey.eq creates its own grey scale, but -e has to work with any colour
table, so it's reliant upon the existing colour lookup functions.

> In case of logarithmic scaling there is a difference too:
> 
> $ r.colors landcover.30m col=grey.log
> $ r.mapcalc 'tryit_old_log=#landcover.30m'
> 
> $ r.colors -g landcover.30m col=grey
> $ r.mapcalc 'tryit_new_log=#landcover.30m'
> 
> $ r.mapcalc 'dif_log=tryit_new_log-tryit_old_log'
> $ r.info -r dif_log
> min=0
> max=10
> 
> Is that as expected?

The algorithm used by grey.log is quite different to that used by -g. 

The former takes a "struct Cell_stats", and generates a "step" (a rule
with the same grey level for the start and end points) for each
category which occurs.

The latter simply divides the range into 100[*] logarithmically equal
steps. This eliminates the need to compute statistics, so there are no
issues with FP data or performance issues with large maps.

[*] I can easily change the number of steps, or make it an option.

BTW: -e and -g aren't mutually exclusive.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list