[gdal-dev] Converting palette image to RBG

Christopher Barker Chris.Barker at noaa.gov
Fri Feb 15 16:52:58 EST 2008


Jean-Claude Repetto wrote:
> I am using ImageMagick :
> convert paletted-image.png -type TrueColor rgb-image.png

well, yes, but I need to do this inside a program, with a subset of the 
entire image, which brings me to:

Frank Warmerdam wrote:
> In fact, it only exists as a python utility in GDAL: pct2rgb.py

Thanks Frank. I've taken a look at that, and I can adapt the code. 
However, this is my use case:

I'm using GDAL to build a mini-map viewer. I need to be able to pull 
pieces of a map out of a gdal.RasterBand, rescale it to a new size, and 
then make it an RGB image.

The other option is to convert the whole thing to RGB, and then do the 
sub-sampling and re-scaling with that (and PIL or wxPython tools). 
However these are big images and I'd rather not have all that data in 
memory as RGB -- the 8-bit format is 1/3 the size.

As I'm doing this on the fly, I'd like it to be fast -- the pct2rgb.py 
code uses numpy, but it looks like it's processing the image line by 
line, and also looping through the color table. I need to do more 
testing to see if this is really too slow, but it would be nice to have 
all that looping in C -- and I can't be the only one that would use such 
functionality.

Another thought -- my workflow may be a bad idea anyway -- should I 
convert to RBG first, and then re-scale it? You must not be able to 
interpolate smoothly with a palleted image..

-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov


More information about the gdal-dev mailing list