Skip to content

Conversation

@rouault
Copy link
Member

@rouault rouault commented Jan 29, 2026

The current logic to compute them is quite naive, and only reasonably works when the shape of the output chunk is similar (in proportion and orientation) to the one of the input chunk. Failing that, inappropriate values are computed leading typically to blurring.

Rework the logic to be closer to a specific case that had already been implemented to deal with discontinuities at the antimeridian, but with modifications. So we compute the transformation of a maximum of 10x10 unit squares in the target pixel space to the source pixel space. If a source polygon retains an approximative rectangular shape with modest rotation, use the width/height of that rectangle to compute XSCALE/YSCALE. Otherwise compute the area of the rectangle and make XSCALE/YSCALE be the inverse of the square root of the area. Average the values for each output polygon, except values that are less than 10% of the maximum scale, to avoid issues with polar discontinuities

Also revise the logic to decide whether we use a 4 input sample per output pixel vs generalized resampling kernel for bilinear and bicubic. Previously we only used the 4-sample formula if not downsampling (with a margin error of 5%). Increase that tolerance to allow up to a 50% downsampling. And emit a debug trace when the generalized formula is used instead of the 4 sample one.

Due to those changes, a few existing expected checksums had to be adjusted. And we also had to adjust a heuristics in the average/mode/Q1/Q3/max/etc. resampling code path that dealt with polar discontinuities to make a related test still pass.

@rouault rouault added this to the 3.13.0 milestone Jan 29, 2026
@rouault rouault force-pushed the warp_scale_geolocation_with_rotation branch 8 times, most recently from adb898a to dc9d6f6 Compare January 30, 2026 03:03
@coveralls
Copy link
Collaborator

Coverage Status

coverage: 71.676% (+0.005%) from 71.671%
when pulling dc9d6f6 on rouault:warp_scale_geolocation_with_rotation
into 4a34dd5 on OSGeo:master.

…is quite different from the source shape

The current logic to compute them is quite naive, and only reasonably
works when the shape of the output chunk is similar (in proportion and
orientation) to the one of the input chunk. Failing that, inappropriate
values are computed leading typically to blurring.

Rework the logic to be closer to a specific case that had already been
implemented to deal with discontinuities at the antimeridian, but with
modifications. So we compute the transformation of a maximum of 10x10
unit squares in the target pixel space to the source pixel space. If a
source polygon retains an approximative rectangular shape with modest
rotation, use the width/height of that rectangle to compute
XSCALE/YSCALE. Otherwise compute the area of the rectangle and make
XSCALE/YSCALE be the inverse of the square root of the area.
Average the values for each output polygon, except values that are less
than 10% of the maximum scale, to avoid issues with polar
discontinuities

Also revise the logic to decide whether we use a 4 input sample per output
pixel vs generalized resampling kernel for bilinear and bicubic.
Previously we only used the 4-sample formula if not downsampling (with a
margin error of 5%). Increase that tolerance to allow up to a 50%
downsampling. And emit a debug trace when the generalized formula is
used instead of the 4 sample one.

Due to those changes, a few existing expected checksums had to be
adjusted. And we also had to adjust a heuristics in the
average/mode/Q1/Q3/max/etc. resampling code path that dealt with
polar discontinuities to make a related test still pass.
@rouault rouault force-pushed the warp_scale_geolocation_with_rotation branch from dc9d6f6 to 7e18bd3 Compare January 30, 2026 16:19
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.

2 participants