[Gdal-dev] Can I manipulate the palette?

Kyler Laird Kyler at lairds.com
Mon Nov 24 09:56:17 EST 2003


On Mon, Nov 24, 2003 at 09:46:36AM -0500, Frank Warmerdam wrote:

> >I see that I can create a ColorTable and I can set it as part of
> >ComputeMedianCutPCT(), but I haven't located a way to set individual
> >entries.  Is this something that's hidden on purpose?  Is there a clean
> >way to manipulate the palette?
> 
> Kyler,
> 
> The GDALComputeMedianCutPCT() produces a PCT that is good for a given RGB
> image.  It doesn't provide any mechanism to "guide" the selection of colors
> for the color table.

I want to do much more than guide it.  I want to build the palette
from scratch.

> However, after the PCT is generated you can alter
> it as you wish, adding, replacing or removing colors.
> 
> Hmm, actually, looking at the GDALColorTable methods there isn't really any
> way to remove entries.  But in a pinch you could just create a new color
> table and copy over only the entries you want to preserve.
>
> The C level colortable functions are:

I'm doing this in Python.  Am I correct that there is no (clean)
way to manipulate the palette from Python?

My "solution" (kludge) is to use PIL to create a 1x1 image with
the desired palette and then open it with GDAL to grab the palette.
I should be able to use StringIO to encapsulate this into something
(subclass) that almost looks reasonable.  I was just hoping that
GDAL provided an interface already.

--kyler



More information about the Gdal-dev mailing list