Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuth & Kaab coregistration spreads NaNs #232

Open
adehecq opened this issue Nov 15, 2021 · 4 comments
Open

Nuth & Kaab coregistration spreads NaNs #232

adehecq opened this issue Nov 15, 2021 · 4 comments
Labels
bug Something isn't working priority Needs to be fixed rapidly

Comments

@adehecq
Copy link
Member

adehecq commented Nov 15, 2021

The Nuth & Kaab coregistration (and I assume other types of coregistration as well) spread NaNs because of the resampling.
An easy way to see it is to run the Nuth & Kaab example and to add some random gaps in the DEM. See attached script (rrnamed to txt so that GitHub does not complain) and figure below.

Figure_1

plot_nuth_kaab.txt

@adehecq adehecq added the bug Something isn't working label Nov 15, 2021
@adehecq
Copy link
Member Author

adehecq commented Nov 15, 2021

A simple solution is to replace the whole _apply_matrix method by something like this:

dem_to_be_aligned_copy = dem_to_be_aligned.copy()
dem_to_be_aligned_copy.shift(-nuth_kaab._meta['offset_east_px']*nuth_kaab._meta['resolution'], -nuth_kaab._meta['offset_north_px']*nuth_kaab._meta['resolution'])
aligned_dem = dem_to_be_aligned_copy.reproject(reference_dem, resampling='cubic')

Note that one can check that the coregistration works well by running Nuth & Kaab a second time and checking the residual translation. The result is best if resampling with cubic. This is probably because in Nuth & Kaab fit function, the raster is resampled using RectBivariateSpline with degree 1.

@adehecq
Copy link
Member Author

adehecq commented Nov 15, 2021

Actually, cubic interpolation spreads the NaNs even more, so bilinear is preferable, see below.

With bilinear interpolation
image

With cubic interpolation
image

See attached script for tests.
plot_nuth_kaab.txt

@erikmannerfelt
Copy link
Contributor

This is most likely due to the dilate_mask argument, which we deemed was a preferable behavior over potentially introducing weird artefacts. I'm not saying this isn't an issue, just that the effect is an intentional "better of two evils"!

#87 (comment)

@adehecq
Copy link
Member Author

adehecq commented Nov 16, 2021

The NaN spread is even worse with two coregistrations in a row, like coreg = xdem.coreg.ICP() + xdem.coreg.NuthKaab() (see attached script and figure).
Turning off the 'dilate_mask' option reduces the gaps, but it is not perfect yet, because currently the apply method is run twice with two items in the CoregPipeline.

image

test_coreg.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority Needs to be fixed rapidly
Projects
None yet
Development

No branches or pull requests

3 participants