[gdal-dev] Modify original ColorTable in VRT & TIFF files

lars.schylberg at blixtmail.se lars.schylberg at blixtmail.se
Thu Apr 22 13:44:05 PDT 2021


Hi, 

I had to deal a lot with palette tiff images a couple of years ago.

What I did was that edited the vrt files with sed inline editing:

Some examples:

Insert a text file after the row that is: /VRTRasterBand dataType="Byte" band="1" The inserted file here is orig_colortable_vrt.txt:

sed -i -e '/VRTRasterBand dataType="Byte" band="1"/r orig_colortable_vrt.txt' image_6.vrt


Remove a certain line that contains "NoDataValue"

sed -i -e '/NoDataValue/d' image_6.vrt
 
There a also a sed commands to delete certain rows. Just read many sed examples.

Have fun / Lars Schylberg


22 april 2021 kl. 20:25, "Hotmail" <rlelamer at hotmail.fr> skrev:

> Hi all,
> 
> I'm looking to modify the original ColorTable, when georeferencing, PNG => gdal_translate +
> gdalwarp => TIFF.
> 
>> gdal_translate -of VRT -a_srs EPSG:4326 file_png file_vrt -a_ullr xxxx
>> gdalwarp -s_srs EPSG:4326 -t_srs EPSG:3857 file_vrt file_tiff
> 
> If I open the VRT file and do the edit manually, the output TIFF file is correct.
> The problem is that I have 524288 files ... so I would like to do the modification automatically,
> via gdal_translate.
> But I don't quite understand using the parameters of the command ...
> 
> • Original VRT & TIFF files
> 
> # VRT
> <VRTRasterBand dataType="Byte" band="1">
> <ColorInterp>Palette</ColorInterp>
> <ColorTable>
> <Entry c1="0" c2="0" c3="255" c4="255" />
> <Entry c1="255" c2="255" c3="255" c4="255" />
> <Entry c1="0" c2="0" c3="0" c4="255" />
> [...]
> <Entry c1="0" c2="0" c3="0" c4="255" />
> </ColorTable>
> </VRTRasterBand>
> 
> # TIFF
> Band 1 Block=63153x1 Type=Byte, ColorInterp=Palette
> Color Table (RGB with 256 entries)
> 0: 0,0,0,255
> 1: 255,255,255,255
> 2: 0,0,0,255
> [...]
> 255: 0,0,0,255
> 
> I want this :
> • Modified VRT and TIFF files
> 
> # VRT
> <VRTRasterBand dataType="Byte" band="1">
> <ColorInterp>Palette</ColorInterp>
> <ColorTable>
> <Entry c1="0" c2="0" c3="255" c4="255" />
> <Entry c1="0" c2="255" c3="0" c4="255" />
> <Entry c1="255" c2="0" c3="0" c4="255" />
> [...]
> <Entry c1="255" c2="0" c3="0" c4="255" />
> </ColorTable>
> </VRTRasterBand>
> 
> # TIFF
> Band 1 Block=63153x1 Type=Byte, ColorInterp=Palette
> Color Table (RGB with 256 entries)
> 0: 0,0,255,255
> 1: 0,255,0,255
> 2: 255,0,0,255
> [...]
> 255: 255,0,0,255
> 
> Whatever I find, redirects me to gdaldem (which I can't use). In gdal_translate, it seems to me
> that the parameter -colorinterp_X might be suitable
> but I can't find any concrete examples (or I have not looked in the right place).
> 
> I want to impose the following parameters:
> Band 1
> Type = Byte
> ColorInterp = Palette
> Color Table (RGB with 256 entries)
> 
> In ColorTable:
> Entry 0 = 0,0,255,255
> Entry 1 = 0,255,0,255
> Entries 2 to 255 = 255,0,0,255
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list