[GRASSLIST:1771] Re: r.patch color table question

Glynn Clements glynn.clements at virgin.net
Sun Nov 16 00:37:27 EST 2003


Richard Greenwood wrote:

> I am using grayscale imagery to fill in blank areas in a color imagery set. 
> I have used r.composite to create composite color images from the rgb 
> channels in the color imagery. To create a corresponding color table for 
> the grayscale imagery, I am using r.composite and specifying the grayscale 
> image for all three channels. This works, but it seems rather inelegant.
> 
> Can anyone suggest a more efficient approach?

You could use r.reclass or r.mapcalc, but you would need to compute
the categories transformation manually. There isn't another tool which
will do the same job as running r.composite with the same map for each
of the three channels.

Bear in mind that you aren't just creating a colour table. You are
changing the category values to match the "encoding" which the colour
maps use. r.patch operates upon categories, not colours.

For a given intensity level k in the range 0 to levels-1, where
"levels" is the argument to r.composite's levels=/lev_[rgb]= options
(the default is 32), the corresponding category is:

	k + k * levels + k * levels * levels
=	k * (1 + levels + levels * levels)
=	k * (1 + (1 + levels) * levels)

E.g. for levels=32:

	category = k * 1057	// 1024 + 32 + 1 = 1057

For an intensity value in the range 0-255, the corresponding value of
k is given by either:

	(x + 128 / (levels - 1)) * (levels - 1) / 256
or:
	x * levels / 256

depending upon whether r.composite's -c switch was used (the former is
with -c, the latter without).

So, for the default r.composite settings (levels=32, without -c), you
should be able to use:

	r.mapcalc 'outmap = (x / 8) * 1057'

[Note: all of this relies upon integer arithmetic; don't try to
calculate or simplify any of the above using real-number arithmetic.]

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




More information about the grass-user mailing list