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

Modify the logic of selection of overviews for non-nearest resampling… #9040

Merged
merged 2 commits into from
Jan 11, 2024

Conversation

rouault
Copy link
Member

@rouault rouault commented Jan 8, 2024

…; add a GDAL_OVERVIEW_OVERSAMPLING_THRESHOLD config option

The current logic reads:

 * Some formats may efficiently implement decimation into a buffer by
 * reading from lower resolution overview images. The logic of the default
 * implementation in the base class GDALRasterBand is the following one. It
 * computes a target_downscaling_factor from the window of interest and buffer
 * size which is min(nXSize/nBufXSize, nYSize/nBufYSize).
 * It then walks through overviews and will select the first one whose
 * downscaling factor is greater than target_downscaling_factor / 1.2.
 *
 * Let's assume we have overviews at downscaling factors 2, 4 and 8.
 * The relationship between target_downscaling_factor and the select overview
 * level is the following one:
 *
 * target_downscaling_factor  | selected_overview
 * -------------------------  | -----------------
 * ]0,       2 / 1.2]         | full resolution band
 * ]2 / 1.2, 4 / 1.2]         | 2x downsampled band
 * ]4 / 1.2, 8 / 1.2]         | 4x downsampled band
 * ]8 / 1.2, infinity[        | 8x downsampled band

With this PR, is is ammended with the following complement:

 * Note that starting with GDAL 3.9, this 1.2 oversampling factor can be
 * modified by setting the GDAL_OVERVIEW_OVERSAMPLING_THRESHOLD configuration
 * option. Also note that starting with GDAL 3.9, when the resampling algorithm
 * specified in psExtraArg->eResampleAlg is different from GRIORA_NearestNeighbour,
 * this oversampling threshold defaults to 1. Consequently if there are overviews
 * of downscaling factor 2, 4 and 8, and that the desired downscaling factor is
 * 7.99, the overview of factor 4 will be selected for a non nearest resampling.

@rouault rouault added this to the 3.9.0 milestone Jan 8, 2024
@coveralls
Copy link
Collaborator

coveralls commented Jan 8, 2024

Coverage Status

coverage: 68.736% (-0.005%) from 68.741%
when pulling 9004633 on rouault:GDAL_OVERVIEW_OVERSAMPLING_THRESHOLD
into ccb472a on OSGeo:master.

@rouault rouault force-pushed the GDAL_OVERVIEW_OVERSAMPLING_THRESHOLD branch from 133fc2a to f6628ca Compare January 8, 2024 21:12
…; add a GDAL_OVERVIEW_OVERSAMPLING_THRESHOLD config option

The current logic reads:
```
 * Some formats may efficiently implement decimation into a buffer by
 * reading from lower resolution overview images. The logic of the default
 * implementation in the base class GDALRasterBand is the following one. It
 * computes a target_downscaling_factor from the window of interest and buffer
 * size which is min(nXSize/nBufXSize, nYSize/nBufYSize).
 * It then walks through overviews and will select the first one whose
 * downscaling factor is greater than target_downscaling_factor / 1.2.
 *
 * Let's assume we have overviews at downscaling factors 2, 4 and 8.
 * The relationship between target_downscaling_factor and the select overview
 * level is the following one:
 *
 * target_downscaling_factor  | selected_overview
 * -------------------------  | -----------------
 * ]0,       2 / 1.2]         | full resolution band
 * ]2 / 1.2, 4 / 1.2]         | 2x downsampled band
 * ]4 / 1.2, 8 / 1.2]         | 4x downsampled band
 * ]8 / 1.2, infinity[        | 8x downsampled band
```

With this PR, is is ammended with the following complement:
```
 * Note that starting with GDAL 3.9, this 1.2 oversampling factor can be
 * modified by setting the GDAL_OVERVIEW_OVERSAMPLING_THRESHOLD configuration
 * option. Also note that starting with GDAL 3.9, when the resampling algorithm
 * specified in psExtraArg->eResampleAlg is different from GRIORA_NearestNeighbour,
 * this oversampling threshold defaults to 1. Consequently if there are overviews
 * of downscaling factor 2, 4 and 8, and that the desired downscaling factor is
 * 7.99, the overview of factor 4 will be selected for a non nearest resampling.
```
@rouault rouault force-pushed the GDAL_OVERVIEW_OVERSAMPLING_THRESHOLD branch from f6628ca to be6481c Compare January 8, 2024 22:26
gcore/gdaldataset.cpp Outdated Show resolved Hide resolved
gcore/gdalrasterband.cpp Outdated Show resolved Hide resolved
Co-authored-by: Alessandro Pasotti <[email protected]>
@rouault rouault merged commit 17a36ae into OSGeo:master Jan 11, 2024
30 checks passed
@tbonfort
Copy link
Member

I am seeing qgis doing some back and forth between the full-resolution data and the first overview, while only doing a small pan. I believe this is due to some numerical instability when calculating the downscaling factor, and the default GDAL_OVERVIEW_OVERSAMPLING_THRESHOLD=1 used.
To reproduce:

  • open a raster in qgis
  • right click on raster layer, select "zoom to native resolution"
  • zoom out one level (one click on the mouse wheel)
  • => when panning, qgis switches ,seemingly randomly, between the first overview level or the full resolution level.

This can be "fixed" by setting GDAL_OVERVIEW_OVERSAMPLING_THRESHOLD=1.01. I believe that the default value used for GDAL_OVERVIEW_OVERSAMPLING_THRESHOLD should be set to 1+epsilon in order to avoid this instability on commonly used zoom levels.

@rouault
Copy link
Member Author

rouault commented Jan 18, 2024

I am seeing qgis doing some back and forth between the full-resolution data and the first overview

should be fixed per #9100

rouault added a commit to rouault/gdal that referenced this pull request Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants