This is useful for georeferenced images or GeoTIFF files that have black borders caused by re-projection or warping.
Georeference the image in QGIS, and export to a GeoTIFF (original.tif
). Use Photoshop to open the GeoTIFF and select the area you want to mask; in the "Layers" palette switch to the "Channels" tab and select the Alpha channel (create one if it doesn't exist). Fill the masked area with "black" in the Alpha channel, as save as a new TIFF (export.tif
). Don't bother with compression when exporting from Photoshop as we are about to convert the image again.
This TIFF won't have geodata, so we will use some command line tools from libgeotiff to fix that.
$ listgeo -no_norm "original.tif" > metadata.geo
$ geotifcp -g metadata.geo "export.tif" map.tif
$ gdal_translate map.tif map2.tif -b 1 -b 2 -b 3 -mask 4 --config GDAL_TIFF_INTERNAL_MASK YES
The map2.tif
file should have the original geodata and a fourth color band for the alpha channel. That last GDAL command can be modified to add other GeoTIFF options such as compression.