[gdal-dev] Set color table in NITF

Cole, Derek dcole at integrity-apps.com
Wed Sep 21 18:28:05 EDT 2011


I am revisiting this because I discovered some of my code that I thought was correct is not actually setting a colortable in my NITF.

        dataBand =  sicdDS->GetRasterBand(1);
        GDALColorTable colorTable(GPI_RGB);


        int index;
        for (int red = 0 ; red < 256; red += 51)
        {
                for (int green = 0 ; green < 256 ; green += 51)
                {
                        for (int blue = 0 ; blue < 256 ; blue += 51)
                        {
                                    GDALColorEntry gce;
                                gce.c1 = red;
                                gce.c2 = green;
                                gce.c3 = blue;
                                colorTable.SetColorEntry(index, &gce);
                                index++;
                        }
                }
        }

        while (index < 256)
        {

                    GDALColorEntry gce;
                gce.c1 = 255;
                gce.c2 = 255;
                gce.c3 = 255;
                colorTable.SetColorEntry(index, &gce);
                index++;
        }
        dataBand->SetColorTable(&colorTable)

The above does NOT set the colortable of the image as expected, and when I do a gdalinfo on the image, the lookup table values look like defaults (256 colors, 1..256 sequentially)

Can you see somethign wrong with the code above as to why it is not setting it? 

Further down in that code I use "dataBand" to do some RasterIO operations that seem to be taking, but its just not letting me modify the lookup table.

Thanks
________________________________________
From: Even Rouault [even.rouault at mines-paris.org]
Sent: Monday, August 29, 2011 6:29 PM
To: gdal-dev at lists.osgeo.org
Cc: Cole, Derek
Subject: Re: [gdal-dev] Set color table in NITF

Le mardi 30 août 2011 00:14:12, Cole, Derek a écrit :
> Hello,
>
> I am trying to create a NITF that uses a color lookup table.
>
> I found the option to add an RGB/LUT to the image, which didnt complain,
> however, when I had my LUT data to the image, it all seems to be kind of
> black and white.
>
> I know when I was displaying the images in my viewer (which I wrote in Qt),
> I had a function to create a 256 element color table, that changed some of
> the values. How would I modify the color table in the NITF?

Use SetColorTable() on the raster band object.

Python example :

from osgeo import gdal
ds = gdal.GetDriverByName('NITF').Create('test.ntf', 1, 1, options =
['IREP=RGB/LUT', 'LUT_SIZE=3'])
ct = gdal.ColorTable()
ct.SetColorEntry( 0, (0,0,0) )
ct.SetColorEntry( 1, (10,10,10) )
ct.SetColorEntry( 2, (20, 20, 20))
ds.GetRasterBand(1).SetColorTable(ct)
ds = None


$ gdalinfo test.ntf
Driver: NITF/National Imagery Transmission Format
Files: test.ntf
Size is 1, 1
[...]
Band 1 Block=1x1 Type=Byte, ColorInterp=Palette
  NoData Value=3
  Color Table (RGB with 4 entries)
    0: 0,0,0,255
    1: 10,10,10,255
    2: 20,20,20,255
    3: 0,0,0,0


>
> Thanks


More information about the gdal-dev mailing list