2

I am currently trying to merge overlapping raster TIFFs into one single, continuous image. Just using Merge results in a raster with borders, and it is unsatisfactory : enter image description here

However, using a pixel function to choose the maximum value present on overlapping parts results in a smooth image, but much of the detail is lost.

How do I merge them such that they look more or less smooth but maintain the details? I can use any Python or GDAL solution

2
  • 1
    Hi can you post the gdal commands you have tried? Is the issue with the result shown in the image the black values?
    – Cushen
    Feb 22 '21 at 0:20
  • 1
    Are you making sure the output cell size is the same as the input rasters?
    – GBG
    Feb 22 '21 at 18:30
2
+25

You might want to play around with different pixel functions than just max (mean, min, first/last image, etc). Depending what type of data your raster represents and what you are trying to do with it, one of these might be more appropriate than the max.

For example if you were working with a DEM, taking the max is going to exaggerate the height, so maybe taking the mean would be a better option.

In contrast, if working with categorical data (e.g. land use) taking the mean would not be appropriate, and taking the max just biases the results towards whichever category happens to have the highest category number. Instead you might want to choose the most common value if you have 3+ rasters overlapping.

If your data is imagery based, if the images are on different days perhaps taking the most recent pixel would be best (assuming you can order the rasters by date).

When combining rasters it is also important to check whether your input rasters have values all in the same range. For example with imagery taken on different days sometimes one image might have particularly high or low values, or a far smaller/larger range of values than the other images. One single extreme value might not be visible to the naked eye in your merged image, but it could definitely throw off the coloring making everything appear to be all roughly the same value. As an example, if a color ramp is stretched from 0 to 100 you'll be able to see the difference between 40 and 60 much better than if that same color ramp is stretched from 0 to 10,000.

0

Is this single band? can you raster calculator to a new image?

the logic would be ((a>0)a+(b>0)b+(c>0)c+(d>0)d)/((a>0)+(b>0)+(c>0)+(d>0))

or in layman's speak.. at the pixel level it would calculate (if image a >0) + (if image b)+ (if image c)+ (if image c)/count of valid images

0

You could have a look at mosaicing the rasters using the gdalbuildvrt function. The result would behave as one merged raster file usable for analysis.

The black borders can be controlled with the No Data settings (Usually, either pixel values 0 or 255: [-srcnodata "value [value...]"] [-vrtnodata "value [value...]"]

See for example also this answer on the questioon to average overlapping sections: Averaging overlapping rasters with gdal

Edit: Addition, as @ycartwhelen suggested, you do not have to specify average/mean resampling algorithm. You can reset the resampling with: -r {nearest (default),bilinear,cubic,cubicspline,lanczos,average,rms,mode}

The gdalwarp function even provides more resampling methods: https://gdal.org/programs/gdalwarp.html

2
  • I already said that averaging the overlapping rasters caused loss of detail, and that I need raster tif, not a vrt. Feb 25 '21 at 20:44
  • As suggested below by @ycartwhelen, you could use different forms of merging such as max, min, first/last image, etc for combining the rasters. After creating a VRT converting using gdal_translate to a tiff is an easy step.
    – PGerrits
    Feb 26 '21 at 12:31

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.