I'm trying to make some height maps with elevation data from https://earthexplorer.usgs.gov/. Since they give you assets in separate TIF tiles, I need to convert them to PNG and stitch them together to the area of land that I'm trying to extrude in Blender. The only problem is, once I run

gdal_translate -of PNG -ot Byte -scale input.tif output.png

with QGIS's terminal, the output png has all it's values 'normalized'. It end up looking like this in photoshop when I try to put the tiles together.

enter image description here

I partially can get around that by tediously adjusting contrast for each tile so they look normal to the eye, but it's always got artifacts in it. Is there a way to avoid this when converting with gdal?

  • is there a reason why you're exporting Byte? That only gives 256 levels. You might get better results using PNG-16 (unless you're after a 'terraced' look), I'm sure I've got blender to handle 16 bit heightmaps from QGIS before.
    – Steven Kay
    Sep 14 '17 at 8:13

It is not about the contrast, the elevation in each scene is different. In other words, the minimum and maximum elevation is different in each scene. The only solution to this problem is that you need to mosaic the DEM scene first to get a the correct elevation.

You need to use Merge tool from Processing toolbox -> GDAL/OGR -> Miscellaneous -> Merge

enter image description here

Make sure to select the proper rater type from the input data. You can check that from Properties -> Metadata and scroll down until you see the Data Type.


-scale will automatically scale down the values to 0 - 255. So the maximum value of each individual file will become 255. As the maximum value is different in each raster, the brightness will be different.

You need to use a fixed scaling:

gdal_translate -of PNG -ot Byte -scale 0 2550 0 255 input.tif output.png

The 2550 should be replaced by a reasonable value for your input data, e.g. the max value of all input files.

Alternative solution:

If the files are correctly georeferenced, you don't need to stitch them with Photoshop. Merge them with gdalmerge or gdalbuildvrt:

gdalbuildvrt -o merged.vrt input_1.tif input_2.tif input_3.tif
gdal_translate -of PNG -ot Byte -scale merged.vrt output.png

(As you have just one max value in the VRT file, you don't need to explicitly set the scaling values)

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.