Closed zdila closed 1 month ago
Gdalwarp with
-r lanczos
can cause aliased edges.
you'll have to explain more the issue with some highlighting to show where you see something wrong. I can't even notice a difference with your 2 screeshots... And provide the input dataset
As animated gif:
And provide the input dataset
It has 160GB so I will provide a description where to download it and create it.
It has 160GB so I will provide a description where to download it and create it.
you can also try to use gdal_translate -projwin or -srcwin to create a minimum reproducer. I don't have 160 GB available on my hard disk!
If I extract small area and transform it, I can't reproduce the issue.
gdal_translate -projwin -422444.0 -1185375.5 -422211.0 -1185563.9 Ortofoto_2021_stred_jtsk_rgb/all.vrt extracted.tif
gdalwarp -s_srs 'EPSG:8353' -t_srs 'EPSG:3857' -tr 0.29858214173896972949 0.29858214173896972949 -r lanczos -of GTiff -co COMPRESS=WEBP -co WEBP_LEVEL=85 -co NUM_THREADS=ALL_CPUS -wo NUM_THREADS=ALL_CPUS -multi extracted.tif stred-extract-warped.tif
Anyway, to reproduce it:
Central part 2021 (RGB)
from https://www.geoportal.sk/en/zbgis/orthophotomosaic/2nd-cycle/gdalbuildvrt -a_srs EPSG:8353 -r lanczos all.vrt *.tif
gdalwarp -s_srs 'EPSG:8353' -t_srs 'EPSG:3857' -tr 0.29858214173896972949 0.29858214173896972949 -r lanczos -of GTiff -co COMPRESS=WEBP -co WEBP_LEVEL=85 -co NUM_THREADS=ALL_CPUS -wo NUM_THREADS=ALL_CPUS -multi -te 2118692.6 6294091.5 2120157.9 6295276.7 all.vrt stred-extract-warped.tif
Created small reproducible testcase:
gdalwarp -s_srs 'EPSG:8353' -t_srs 'EPSG:3857' -tr 0.29858214173896972949 0.29858214173896972949 -r lanczos -of GTiff -co COMPRESS=WEBP -co WEBP_LEVEL=85 -co NUM_THREADS=ALL_CPUS -wo NUM_THREADS=ALL_CPUS -multi extracted.tif warped.tif
There is lot of extra in the command. This simplified one makes almost similar result:
gdalwarp -s_srs EPSG:8353 -t_srs EPSG:3857 -r lanczos -of GTiff extracted.tif warped2.tif
I think that maybe the special input SRS EPSG:8353 plays some role. For testing the hypothesis I tried the following command and the result looks better to my eyes.
gdalwarp -s_srs EPSG:3067 -t_srs EPSG:3857 -r lanczos -of GTiff extracted.tif warped3.tif
Now please try with https://drive.google.com/file/d/1KOAjpfTy98o0eiVEnLJgnw3BPAOOW0bv/view?usp=sharing and same command and the issue will not reproduce. I wonder what difference between these two files could cause that aliasing.
and the issue will not reproduce.
actually it does, for example when comparing the cubicspline vs lanczos around coordinate 2365033.68, 6240237.04 in EPSG:3857
I've made a significant breakthrough in debugging this. The following patch disabling the Lanczos optimized code path (used since 12 years...) seems to fix the aliasing issue.
diff --git a/alg/gdalwarpkernel.cpp b/alg/gdalwarpkernel.cpp
index 565a6657a1..8f687abbd4 100644
--- a/alg/gdalwarpkernel.cpp
+++ b/alg/gdalwarpkernel.cpp
@@ -3566,7 +3566,7 @@ static GWKResampleWrkStruct *GWKResampleCreateWrkStruct(GDALWarpKernel *poWK)
psWrkStruct->padfRowImag =
static_cast<double *>(CPLCalloc(nXDist, sizeof(double)));
- if (poWK->eResample == GRA_Lanczos)
+ if (0 && poWK->eResample == GRA_Lanczos)
{
psWrkStruct->pfnGWKResample = GWKResampleOptimizedLanczos;
actually it does, for example when comparing the cubicspline vs lanczos around coordinate 2365033.68, 6240237.04 in EPSG:3857
Hmm... In my case I see no problem there. I compare warped2.tif
with extracted2.tif
and the only relevant difference i see there is a global 1px offset.
Please post a screenshot so I could see your result. Thank you.
Mine is like this:
Please post a screenshot so I could see your result
Lanczos:
vs cubic spline:
Thank you. Strange that I can't reproduce it with that extracted2.tif
file (and you can). I used Debian linux testing: GDAL 3.9.2, released 2024/08/13
. It would be more logical for me if I could reproduce it on both files as you can. Will try more tomorrow.
Fix in #11046
Workaround: if just reprojecting without trying to downsample/oversample, adding -wo XSCALE=1 -wo YSCALE=1
will avoid the issue
Wow! That's a lot of code!
I've compiled your fork/branch (GDAL 3.11.0dev-7727dbaa84, released 2024/10/18
) and for me it works. Also the workaround (-wo XSCALE=1 -wo YSCALE=1
) does with the distro gdal.
Big thank you!
What is the bug?
Gdalwarp with
-r lanczos
can cause aliased edges.lanczos:
cubic:
I have three input vrt files but I can reproduce it only on single one.
Steps to reproduce the issue
Versions and provenance
Tried with 2 versions:
Additional context
Tried also with no success:
-co TILED=YES -co BIGTIFF=YES