[GRASS-user] RGB to Grayscale
Glynn Clements
glynn at gclements.plus.com
Thu May 10 13:14:31 EDT 2007
Travis Kirstine wrote:
> I am trying to convert a RGB image to a single band grayscale image by
> converting the RGB to HIS then exporting the Hue and Intensity (I
> would like to export a grayscale geotiff with gdal). Am I correct in
> that a "true" greyscale image is just the hue and intensity,
To convert to greyscale, you would normally just use the intensity.
Also, note that the "intensity" map generated by i.rgb.his is
completely bogus. For a sane intensity calculation, use r.mapcalc,
e.g.:
r.mapcalc 'intensity = (red + green + blue) / 3'
or:
r.mapcalc 'intensity = 0.30 * red + 0.59 * green + 0.11 * blue'
The first uses equal weights, the latter the NTSC weights (used for
generating the monochrome (Y) component of a composite video signal).
For a suitable colour table use e.g.:
[for 0 - 255]
r.colors intensity color=rules
0 black
255 white
end
[for 0.0 - 1.0]:
r.colors intensity color=rules
0 black
1 white
end
If you use "color=grey", the colour table will map black/white to the
minimum/maximum values which actually occur in the map, which is
incorrect if the map doesn't cover the entire range.
[I'll add these colour tables to CVS; they're likely to be quite
common.]
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list