NeoGeographyToolkit / StereoPipeline

The NASA Ames Stereo Pipeline is a suite of automated geodesy & stereogrammetry tools designed for processing planetary imagery captured from orbiting and landed robotic explorers on other planets.
Apache License 2.0
478 stars 168 forks source link

Create better weights in dem_mosaic #381

Open oleg-alexandrov opened 1 year ago

oleg-alexandrov commented 1 year ago

The dem_mosaic tool performs seamless blending of DEMs. To do that, each DEM is assigned a weight image, with one weight per DEM pixel. Weights decay to 0 at each DEM boundary. So, dem_mosaic does a weighted average of the DEMs, and since each DEM's weight falls off to 0 at its boundary, its contribution gently gets reduced to nothing by the time one gets there, so the combined DEM becomes seamless.

The current weights are based on the Manhattan distance, so, if the DEM boundary is a rectangle, the weight looks like the roof of a house. (The weight is forced to plateau at some distance inward, as otherwise one can't do per-tile-processing uniquely, so the top pointy part of the roof gets flattened, getting eventually a truncated pyramid as the weight.)

The problem is that when the DEM has complicated and noisy boundary, the Manhattan distance results in something not pretty. One hack used in this tool is to blur the resulting weight (option --weights-blur-sigma). Unfortunately, it is not possible to easily blur a function which is supposed to drop off to 0 so the new blurred function does not go beyond the footprint of the original function, so where the original weight is 0 the new blurred weight stays 0, but where both are non-zero, the blurred weight is nicer than the original one, and smoothly decays to 0.

The resulting logic kind of works, more or less, but for a big blur, like 200 pixels, and very complicated geometry the resulting weight is acting out, resulting in a seam in the final blended DEM.

All current logic for creation of weights need to be thrown out. A new function needs to be added, which, given a 2D shape, finds a smooth weight which decays to 0 when moving from inwards to the shape boundary. When moving in reverse, from the boundary inwards, it should grow, but then plateau, also smoothly. Moreover, it should take as input a parameter to control the smoothness of the transition, both at the boundary of shape, and where it plateaus.

A good initial solution for this is the truncated Euclidean distance to boundary. Then it needs to be made smoother, somehow, while still staying within the shape footprint. This will take some work.