[gdal-dev] Interaction between no data and resampling

Laurențiu Nicola lnicola at dend.ro
Mon Jan 16 03:58:28 PST 2023


Hello,

I've been looking over the docs and the code, but I'm still a little confused about how masking and/or no data are handled during resampling in GDAL. I'm interested mostly in the `cubic` and `average` resamples, but I assume the answers will apply to the other modes just as well.

In my understanding:
 * `cubic` will happily include "no data" values in the computation, likely outputting not very useful results
 * `average` will ignore no data input pixels; but how does average pick the weights? The `gdal_translate` docs say "Starting with GDAL 3.1, this is a weighted average taking into account properly the weight of source pixels not contributing fully to the target pixel". I assume that's mostly unrelated.
 * the `-srcnodata` docs and `gdalwarpkernel.cpp` suggest that masked pixels are not included in the computation (unlike those of no data?)
I know two ways of handling masked/no data pixels during resampling:
 * ignore them and rescale the remaining weights of the input pixels (e.g. a 4x4 grid in the `cubic` case), outputting no data if there's no valid pixel among the inputs -- this seems "ideal"
 * output no data if any of the input (e.g. 4x4 grid) pixels are no data
The latter method can be simulated in a reasonably easy way by making a validity mask, resampling it with the same method, then thresholding it to get a new mask which only keeps the "pure" pixels. It might even be possible (but maybe not too easy) to implement do this with a VRT. But its disadvantage is that it tends to expand the invalid areas.

So my main question if there's a supported way to handle this in GDAL (using band masks?), and what does it do (will I get the "ideal" result from above?).

Regards,
Laurentiu Nicola
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20230116/8f3f3fc0/attachment.htm>


More information about the gdal-dev mailing list