[GRASS-user] RGB to Grayscale

Hi All,
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, and is it
possible to merge the bands to a single band image? Any help would be
great

--
Travis K.

Toronto, Canada
------------------------------------------------------------
"She knows there's no success like failure
And that failure's no success at all."
-Bob Dylan-
------------------------------------------------------------

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@gclements.plus.com>

On Thu, May 10, 2007 at 06:14:31PM +0100, Glynn Clements 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?

Markus

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.:

  http://en.wikipedia.org/wiki/HSV_color_space

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

Glynn Clements wrote:

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

did something interesting get lost after "Note that the" ?

Hamish

Hamish wrote:

> 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

did something interesting get lost after "Note that the" ?

No.

I think that I was about to write something like "Note that the
calculation performed by rgb.hsv.sh ..." before rewording it.

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