[GIS] How to remove black edges on georeferenced images with GDAL

gdal

After an image has been georeferenced the transformation creates black edges, how could I set these to white instead of black using GDAL?

Would I have to somehow create a colour table and set nodata to white?

Best Answer

A nodata value is just that, no data. So the idea of having it white, black, or any other colour within the dataset doesn't make sense. Now, obviously when you load an image into a GIS, you have to represent nodata as something, and this is, in Quantum GIS at least, either whatever is underneath, or if there is nothing then the project's background colour. So there is a decoupling of what nodata means, how it is stored, and how it is represented.

If you're getting black regardless of the background colour of the GIS you're using, then the chances are GDAL hasn't set a nodata value at all, and it just defaults to black pixels. So you need to explicitly tell GDAL how you want nodata to be stored. With gdalwarp you use the -dstnodata command line switch to achieve this. You may find that nodata values in the source image aren't carried over in a warp operation, in which case you need to set it explicitly with -srcnodata. If you want to override an image's nodata vaue, you can do that with gdal_translate -a_nodata ....

Related Question