2

==== Edit =====

Issue tracked to strange behaviour of gdal_warp when -dstalpha is specified and source is RGBA.

I had assumed that the grey,green,blue tiffs (see example below) were genuine and people would be familiar with them - meaning something like luminence, green, blue (i.e. kind of similar to analogue TV).

However, it turns out that this was in fact a standard RGB file, where gdal_warp had 'lost' the TIFF colourinterp value for the 1st band.

This seems to happen if you run gdalwarp on an RGBA image (i.e. with an existing alpha band), and also include the -dstalpha parameter. The result is a 5-band file with the colorinterp value for red replaced by 'grey'. If you later ask a gdal program to remove the alpha band, you are left with an apparent 'grey, green, blue' image. As most of my source maps were RGB but some were RGBA, passing them all through the same script was producing a mix of RGB and GGB results.

Command causing the problems: gdalwarp -overwrite -s_srs EPSG:27291 -tr 10 10 -t_srs EPSG:2193 -r bilinear -dstalpha -of GTiff NZMS001_N128_1965_geo_crop.tif NZMS001_N128_1965_geo_warp.tif

e.g. of erroneous file:

mbriggs@maps:~/tmp$ gdalinfo NZMS001_N128_1965_geo_warp.tif

Driver: GTiff/GeoTIFF
... Band 1 Block=4187x1 Type=Byte, ColorInterp=Gray
Band 2 Block=4187x1 Type=Byte, ColorInterp=Green
Band 3 Block=4187x1 Type=Byte, ColorInterp=Blue
Band 4 Block=4187x1 Type=Byte, ColorInterp=Undefined
Band 5 Block=4187x1 Type=Byte, ColorInterp=Alpha

After conversion to 3-band:

mbriggs@maps:~/tmp$ gdalinfo NZMS001_N128_1965_geo_nztm.tif

Driver: GTiff/GeoTIFF
.... Band 1 Block=4187x1 Type=Byte, ColorInterp=Gray
Band 2 Block=4187x1 Type=Byte, ColorInterp=Green
Band 3 Block=4187x1 Type=Byte, ColorInterp=Blue
mbriggs@maps:~/tmp$

Fix:

run:

gdal_translate -b 1 -b 2 -b 3

on all files to ensure all are RGB (and not RGBA) before running gdal_warp -dstalpha.

=====

How do I convert a geotiff from grey, green, blue colour map to red, green, blue?

gdalbuildvrt won't let me use my collection of sheets as some are in grey, green, blue and some are red, green, blue.

  • 2
    Gdal_Translate -b 1 -b 2 -b 3 will store the bands as RGB, gdal_translate -b 1 -expand RGB will expand band 1 into a monochrome RGB (RGB but each band has the same value)... is that what you're after? What's Grey, Green, Blue about? Is grey really supposed to be red? Can you include a sample in your question? – Michael Stimson May 7 '15 at 23:49
  • 2
    You mention color maps, which are tables that give an RGB value(s) to values in a raster. Then there's an RGB tif as Michael mentions, which has three separate bands/rasters as part of a single image. It's unclear exactly what you have/are trying to do. Do the rasters all have the same value schemes? Do you just need to edit one set or the other to point at a different color map instead of having two different maps? Please edit your question to provide some more detail about the rasters, their values, and exactly what commands you're using. – Chris W May 8 '15 at 0:23
  • 1
    Rather than edit the solution into your question, you (or perhaps @MichaelMiles-Stimson ) should post it as an answer now that the question is reopened. And it wouldn't hurt to add the clarifying information to the question as well, or change at least change the term "colour map" to "bands" since I think that's the biggest source of confusion. – Chris W May 11 '15 at 0:31

Your Answer

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

Browse other questions tagged or ask your own question.