1

I'm creating a mosaic from many sentinel images with a bunch of overlapping areas, although I'm trying to understand what is criteria. For example:

1

This is a small piece totally clear of clouds

2

And this is a larger piece with many clouds

3

This is the result of the merge using rasterio and gdal

I used rasterio.merge and gdal_merge. Both brings me the same result, but don't understand the algorithm method yet. How can I tell the tool to preserve the image with fewer clouds as possible? Which method are these algorithms using to preserve the larger raster and not the cleanest (no clouds)?

It would be absolutely awesome if I could select the raster with fewer clouds to be merged for this mosaic. Is there a way to choose the raster I want to keep?

4
  • 1
    From the documentation gdal.org/programs/gdal_merge.html In areas of overlap, the last image will be copied over earlier ones.
    – user30184
    Commented Dec 21, 2020 at 17:34
  • Thx @user30184 now I'm curious to understand the rasterio.merge method. There's no information at all on their documentation =/ Commented Dec 22, 2020 at 14:36
  • 1
    The documentation points to ask questions here rasterio.groups.io/g/main
    – user30184
    Commented Dec 22, 2020 at 14:42
  • You say there is no information in the rasterio docs but my answer shows that there is. Could you share how you searched? Maybe the docs need improvements. Commented Dec 23, 2020 at 11:37

2 Answers 2

3

The documentation https://rasterio.readthedocs.io/en/latest/api/rasterio.merge.html says:

"Input files are merged in their listed order using the reverse painter’s algorithm (default) or another method."

And for the available methods predefined by rasterio:

first: reverse painting
last: paint valid new on top of existing
min: pixel-wise min of existing and new
max: pixel-wise max of existing and new

You can also write your own function, for example for a median or average of the files.

For your use case of removing clouds, you will probably not get good results from the predefined functions, a min for example would leave you without white clouds but with their dark shadows.

1

The order of inputs matters, give as an input first the cloudy image, then the not cloudy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.