[GIS] create blended images with GDAL command line utilities

gdalopen-source-gis

I've written a program in Python with GDAL bindings that generates a single band georeferenced GeoTIFF as output. From there I use the GDAL commandline tool gdaldem to colorize that image to highlight certain classes of pixels. I'd like to also lay it on top of a basemap DEM as final output but I need to do this procedurally in my program as opposed to load both layers into a GIS tool and blend from there.

Are there any GDAL command line utilities I can use to blend two GeoTIFFs together and output a pretty png?

Here's a specific example with some random datasets:

  DEM                                  Pixels


  Pixels + DEM Blended (This is what I want to do with command line tools)

Update:

I ended up using the blend function from PIL like this:

basemap_image = Image.open('basemap.png').convert('RGBA')
overlay_image = Image.open('overlay.png').convert('RGBA')
combined = Image.blend(basemap_image, overlay_image, 0.8)
combined.save("out.png")

Best Answer

You're going to want to use the Python imaging library. PIL.

You will want to load up the first image of the DEM and make sure its in an RGBA format.

from PIL import Image

dem_image = Image.open('dem.png').convert('RGBA')
color_pixels = Image.open('pixels.png').convert('RGBA')

combined = dem_image.paste(color_pixels, (0,0), color_pixels)

Might need to make sure your color_pixels image has an alpha layer as that's what is used for paste. Otherwise you will have to go through it and create a transparency layer in color_pixels by iterating over the values and setting white to an alpha channel.

Hope that helps, or at least gets you started.