I have 1-band GeoTIFF file. The color interpretation for band is gray. I want a color table in order to transform my Col.tiff to Col.jpeg or Col.png.

I tried putting a color table in this tiff via a .vrt:

gdal_translate -of VRT  Col.tiff Col.vrt

then adding in the .vrt:

   <Entry c1="0" c2="0" c3="255" c4="240"/>
   <Entry c1="0" c2="0" c3="254" c4="240"/>
   <Entry c1="0" c2="0" c3="253" c4="240"/>
   <Entry c1="0" c2="0" c3="252" c4="240"/>

And translate again :

gdal_translate Col.vrt Col.tiff

But it answered:

Warning 1: Unable to export color table to GeoTIFF file.  Color tables can only be written to 1 band or 2 bands Byte or UInt16 GeoTIFF files.

How can I do it?

For information, there is gdalinfo for the Band:

Band 1 Block=55x18 Type=Float64, ColorInterp=Gray
  Description = Something
    GRIB_REF_TIME=1401926400 sec UTC
    GRIB_VALID_TIME=1401926400 sec UTC
  • What max/min values does your tif have? It is Float64, so how should this decimal value correspond to the integer values for a colour palette? – AndreJ Jul 4 '14 at 14:22
  • Error says that output must be of type Byte or UInt16. Perhaps you should add "-ot UInt16" into the gdal_translate command. – user30184 Jul 4 '14 at 17:02
  • Thanks, it works now, I just need to find the good colors :) – Faquarl Jul 7 '14 at 8:02
  • @AndreJoost What I've done is taking max/min values and dividing them between 255 classes. Then, for each value, I put a color. – Faquarl Jul 18 '14 at 10:56
  • Finally I made a Python script to make a new tiff with the same informations except there are 4bands (rgba) – Faquarl Jul 18 '14 at 10:58

with gdal, you can color an image based on gdal_dem (color_relief)

the syntax of the color configuration file is derived from the one supported by GRASS r.colors utility. ESRI HDR color table files (.clr) also match that syntax. The alpha component and the support of tab and comma as separators are GDAL specific extensions

aspect: aspect oriented grey colors
aspectcolr: aspect oriented rainbow colors
bcyr: blue through cyan through yellow to red
bgyr: blue through green through yellow to red
byg: blue through yellow to green
byr: blue through yellow to red
celsius: blue to red for degree Celsius temperature
corine: EU Corine land cover colors
curvature: for terrain curvatures (from v.surf.rst and r.slope.aspect)
differences: differences oriented colors
elevation: maps relative ranges of raster values to elevation color ramp
etopo2: colors for ETOPO2 worldwide bathymetry/topography
evi: enhanced vegetative index colors
gdd: accumulated growing degree days
grey: grey scale
grey.eq: histogram-equalized grey scale
grey.log: histogram logarithmic transformed grey scale
grey1.0: grey scale for raster values between 0.0-1.0
grey255: grey scale for raster values between 0-255
gyr: green through yellow to red
haxby: relative colors for bathymetry or topography
ndvi: Normalized Difference Vegetation Index colors
population: color table covering human population classification breaks
population_dens: color table covering human population density classification breaks
precipitation: precipitation color table (0..2000mm)
precipitation_monthly: precipitation color table (0..1000mm)
rainbow: rainbow color table
ramp: color ramp
random: random color table
rstcurv: terrain curvature (from r.resamp.rst)
rules: create new color table based on user-specified rules read from stdin
ryb: red through yellow to blue
ryg: red through yellow to green
sepia: yellowish-brown through to white
slope: r.slope.aspect-type slope colors for raster values 0-90
srtm: color palette for Shuttle Radar Topography Mission elevation
terrain: global elevation color table covering -11000 to +8850m
wave: color wave

You should be able export RGB JPEG using gdal_translate with [-expand {gray|rgb|rgba}] flag. You should use command like this:

gdal_translate -of jpeg -expand rgb -a_nodata 255 -co worldfile=yes col.vrt col.jpg

There is included -a_nodata to leave nodata pixels white not black and -co worldfile=yes to include georeferencing file. However I'm not sure about defining color table for input float data type, because definition of VRT driver states:

ColorTable: This element is parent to a set of Entry elements defining the entries in a color table. Currently only RGBA color tables are supported with c1 being red, c2 being green, c3 being blue and c4 being alpha. The entries are ordered and will be assumed to start from color table entry 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.