[gdal-dev] convert Grayscale to RGB and, after georeferencing, back

Even Rouault even.rouault at spatialys.com
Fri Jun 17 01:10:03 PDT 2016


Le vendredi 17 juin 2016 09:01:43, Mark Johnson a écrit :
> During the process georeferencing a Grayscale image, the image must be
> converted to a RGB image (-expand rgb -ot Byte) before calling
> gdal_translate setting the GCP's.

You can run gdal_translate and gdalwarp directly on your greyscale image. No 
need for the RGB intermediate.

> 
> After gdalwarp, the image is of course then RGB (3 Bands)
> - and is rendered looking as a Grayscale image in QGIS
> 
> My question is: how to convert this back to the original Grayscale?

gdal_translate rgb.tif grey.tif -b 1

> 
> I assume, during the '-expand', the gray values have been separated into
> the 3 bands according to some default logic so that it renders as a
> Grayscale image when viewed.

The logic of -expand rgb , from a greyscale image, is just to replicate each 
grey value on the R,G,B channels :-)

> 
> I have seen samples of converting a (truly) coloured image to Grayscale:
> gdal_calc.py -A input.tif --A_band=1 -B input.tif --B_band=2 -C input.tif
> --C_band=3 --outfile=result.tif --calc="A*0.2989+B*0.5870+C*0.1140"
> 
> Would it be something in this form?

You can do this but as A=B=C, gdal_translate -b 1 will do the same more 
efficiently :-)

> 
> Mark Johnson, Berlin, Germany

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list