[gdal-dev] Convert RGBA geotiff to color table
Oliver Eichler
oliver.eichler at gmx.de
Mon Mar 5 03:51:51 EST 2012
Hi,
this question was discussed around 2004 but with no real result. That's why I would like to raise it again. (http://lists.osgeo.org/pipermail/gdal-dev/2004-September/004203.html)
I have several scanned paper maps (RGB). As there is a lot of side information at the borders, which is bad if you want to stitch the maps together, I added an alpha channel and used gimp to remove the borders. Thus my maps have a transparent irregular border and a RGBA color space.
The referencing went smooth with the help of GDAL. But now I am stuck. I want to reduce the map's colors to 8bit color table. But of course I want to keep the transparent borders, too. In theory no problem as there is NODATA. However rgb2pct.py fails for the same reasons as 2004. I had a look into the python code. I guess the major problem is, that ComputeMedianCutPCT() only takes RGB bands.
If I use gdalinfo with one of my files I see:
Band 1 Block=256x256 Type=Byte, ColorInterp=Red
NoData Value=255
Overviews: 8888x7947, 4444x3974, 2222x1987, 1111x994
Band 2 Block=256x256 Type=Byte, ColorInterp=Green
NoData Value=255
Overviews: 8888x7947, 4444x3974, 2222x1987, 1111x994
Band 3 Block=256x256 Type=Byte, ColorInterp=Blue
NoData Value=255
Overviews: 8888x7947, 4444x3974, 2222x1987, 1111x994
Band 4 Block=256x256 Type=Byte, ColorInterp=Alpha
NoData Value=255
Overviews: 8888x7947, 4444x3974, 2222x1987, 1111x994
Thus, as each band seems to know a no data value, wouldn't it be possible to use that to define a transparent color (255,255,255) and to assign pixels to that color? Right at the moment rgb2pct assigns (248, 248, 248) to the transparent pixels. And others pixels in the map, too.
I just thought this is a very common task to do. But it seems not. Or do I think into the wrong directions? How is the recommended approach to convert RGBA to an 8 bit color table with no data entry?
Thanks for help
Oliver
More information about the gdal-dev
mailing list