[Gdal-dev] Conversion to Grayscale
Frank Warmerdam
fwarmerdam at gmail.com
Fri Dec 3 13:49:59 EST 2004
On Fri, 03 Dec 2004 09:57:15 -0800, Chris Hodgson
<chodgson at refractions.net> wrote:
> Do any of the existing gdal tools support converting a color (RGB or
> paletted) image to a grayscale image? I've been using ImageMagick
> "convert" for this, but it takes ridiculously long to do - ie. I can
> reproject the image faster than I can grayscale it - even without doing
> any histogram balancing. I'm guessing it would be relatively easy to
> write a python script to do this - however I know nothing of Python, let
> alone the gdal interface. Has anyone done this already?
Chris,
Do you want a "proper" RGB to greyscale conversion or is
it sufficient to just take any one of the bands and use it as
greyscale? I believe a "proper" conversion would involve
a colorspace transformation on the RGB image into IHS or
something like that, and then taking the intensity. This is
not conveniently available in GDAL but could be implemented
in Python.
However, if the file is really just a greyscale image represented
in RGB then you could use the -b switch to pick out one band
from the source image to use as the output greyscale image.
eg.
gdal_translate -b 1 in.tif out.tif
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent
More information about the Gdal-dev
mailing list