Reader resampling_method
has no effect
#646
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
@DanSchoppe there are now two resampling options Lines 91 to 92 in 775ecfd
At zoom 17 there are no |
Beta Was this translation helpful? Give feedback.
-
@DanSchoppe Hope those example will help a bit more Something we need to remember is that when we are doing Lines 136 to 140 in 775ecfd WarpResampling https://gdal.org/api/gdalwarp_cpp.html#_CPPv415GDALResampleAlg
Let's check the influence of both import numpy
from rio_tiler.io import Reader
with Reader('https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/15/T/VK/2023/10/S2B_15TVK_20231008_0_L2A/TCI.tif') as cog:
img_cubic = cog.tile(
tile_x=31588,
tile_y=47192,
tile_z=17,
reproject_method="cubic",
)
img_near = cog.tile(
tile_x=31588,
tile_y=47192,
tile_z=17,
reproject_method="nearest",
)
print("Reproject cubic vs nearest (WarpedVRT)")
print(numpy.array_equal(img_cubic.array, img_near.array))
print()
img_cubic = cog.tile(
tile_x=31588,
tile_y=47192,
tile_z=17,
resampling_method="cubic",
)
img_near = cog.tile(
tile_x=31588,
tile_y=47192,
tile_z=17,
resampling_method="nearest",
)
print("Resampling cubic vs nearest (WarpedVRT)")
print(numpy.array_equal(img_cubic.array, img_near.array))
print()
img_mode = cog.tile(
tile_x=31588,
tile_y=47192,
tile_z=17,
resampling_method="mode",
)
img_near = cog.tile(
tile_x=31588,
tile_y=47192,
tile_z=17,
resampling_method="nearest",
)
print("Resampling mode vs nearest (WarpedVRT)")
print(numpy.array_equal(img_mode.array, img_near.array))
print()
☝️ When we are passing different values for Let's check when we are not using WarpedVRT (so no reprojection) import numpy
from rio_tiler.io import Reader
with Reader('https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/15/T/VK/2023/10/S2B_15TVK_20231008_0_L2A/TCI.tif') as cog:
print("Check 'resampling' when no-projection (no WarpedVRT)")
bounds = cog.tms.xy_bounds(31588, 47192, 17)
img_cubic = cog.part(
bounds,
bounds_crs=cog.tms.rasterio_crs,
dst_crs=cog.crs,
resampling_method="cubic",
width=512,
height=512,
)
img_near = cog.part(
bounds,
bounds_crs=cog.tms.rasterio_crs,
dst_crs=cog.crs,
resampling_method="nearest",
width=512,
height=512,
)
print("Resampling cubic vs nearest")
print(numpy.array_equal(img_cubic.array, img_near.array))
print()
|
Beta Was this translation helpful? Give feedback.
Ooo I think I know what's going on 😬
when we are doing reprojection (using WarpedVRT) we are creating a VRT which is aligned with the
bounds
(This is to make sure we fetch the overviews)rio-tiler/rio_tiler/reader.py
Lines 360 to 366 in 775ecfd
Because the VRT will be of the same size as the desired output, there will be no
downscaling/upscaling
happening thererio-tiler/rio_tiler/reader.py
Line 226 in 775ecfd
which is why the
resampling_method
will have no effect 😭