[gdal-dev] can't remap a geotiff via gdalwarp

Frank Warmerdam warmerdam at pobox.com
Tue Feb 5 16:33:11 EST 2008


John Mitchell wrote:
> Hi,
> 
> I am having difficulty remapping all the 0,0,0 pixels into 0,0,1 via 
> gdalwarp.
> I am running the following command:
> gdalwarp.exe -srcnodata "0 0 0" -dstnodata "0 0 1" -rc inputfile.tif 
> outputfile.tif
> 
> I have attached the gdalinfo listing for both the inputfile and the 
> outputfile.
> 
> I have also attached a gdalinfo listing for a geotiff that I am able to 
> remap from 0,0,0 to 0,0,1 and it is called 256_w4.info.

John,

The problem input file is not RGB (while the one that works is).  The
problem input is paletted.  That is your nodata pixels have a value of "0"
and a color table entry that indicates this should be displayed as "0,0,0".

You could do -srcnodata 0 -dstnodata 1 and then all pixels with a value of
zero would be remapped to 1, but the color table entry for 1 is
3,8,21 which is quite a bit more "off black" than 0,0,1.

Basically, it is hard to accomplish exactly what you want with a paletted
image.  If you want to do it you have a couple options.

1) Convert the paletted image to RGB (3 bands) before doing your work.
This can be accomplished with the GDAL Python script pct2rgb.py.  Then
do your 0,0,0 0,0,1 conversion.

2) Merge two colors in your paletted image.  From a quick skim, pixel
values 1 is likely closest to zero.  You could convert 0 to 1, and also
try and modify palette entry "1" to be somewhere between 0,0,0 and 3,8,21
to reduce the visual effect on your image.  (I can provide VRT based details
on how to do this if you want).

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org



More information about the gdal-dev mailing list