[GRASS-user] RGB to Grayscale

Glynn Clements glynn at gclements.plus.com
Sat May 12 15:19:41 EDT 2007

Markus Neteler wrote:

> > 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.
> Should be reported as bug then/fixed?

Probably not; presumably, the existing behaviour was useful for
something, otherwise it wouldn't have been written that way. But the
result isn't what most people would consider "intensity".

The most common RGB to intensity transformations are either an
unweighted mean or weighted a mean using the NTSC weights (30/59/11).

At most, the manual page should document the calculation.

      scaler = (double) rowbuffer[0][sample];
      scaler /= 255.0;
      scaleg = (double) rowbuffer[1][sample];
      scaleg /= 255.0;
      scaleb = (double) rowbuffer[2][sample];
      scaleb /= 255.0;
      high = scaler;
      if (scaleg > high)
	high = scaleg;
      if (scaleb > high)
	high = scaleb;
      low = scaler;
      if (scaleg < low)
	low = scaleg;
      if (scaleb < low)
	low = scaleb;
	calculate the lightness (intensity)
      intens = ((high + low) / 2.0);

IOW: i = (min(r,g,b) + max(r,g,b))/2

Note that the 

Beyond that, it might be worth resurrecting rgb.hsv.sh and hsv.rgb.sh
from 5.3. Although the V of HSV still isn't reasonable for a normal
greyscale conversion (v = max(r,g,b)), the RGB<->HSV conversion
performed by those scripts is the usual one, e.g.:


Glynn Clements <glynn at gclements.plus.com>

More information about the grass-user mailing list