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

Worse image quality with tiles cut using rio-tiler than GDAL #662

Closed
Plantain opened this issue Dec 14, 2023 · 4 comments
Closed

Worse image quality with tiles cut using rio-tiler than GDAL #662

Plantain opened this issue Dec 14, 2023 · 4 comments

Comments

@Plantain
Copy link

Plantain commented Dec 14, 2023

When I use rio-tiler directly on (space-projected) tiffs, the quality of the tiles is noticeably worse than if I first cut them to GoogleMapsCompatible COG's using gdal.

I think given GDAL is the backend of rasterio/rio-tiler, and it's cutting the same size output tiles, the result should be the same quality if not pixel-identical.

Data: http://static.skysight.io/rio-bug/orig.tiff
Warp command: gdalwarp -multi -co TILED=YES -wo NUM_THREADS=64 -co BIGTIFF=YES -t_srs EPSG:3857 -of COG -co QUALITY=100 -co COMPRESS=JPEG -co TILING_SCHEME=GoogleMapsCompatible -co ZOOM_LEVEL=7 -co BLOCKSIZE=512 --config GDAL_TIFF_OVR_BLOCKSIZE 512 orig.tiff reproj.tiff

Code:

from rio_tiler.io import Reader
with Reader("orig.tiff") as src:
    img = src.tile(226,162,8,512)
    f = open("orig.png", "wb")
    f.write(img.render())

with Reader("reproj.tiff") as src:
    img = src.tile(226,162,8,512)
    f = open("reproj.png", "wb")
    f.write(img.render())

rio-tiler reprojected and extracted tile:
orig

gdal reprojected and rio-tiler extracted tile:
reproj

The difference is subtle but if you zoom right in, you can see the GDAL reprojected tile appears to have double(?) the vertical pixel resolution.

Screenshot 2023-12-14 at 10 59 40 am
Screenshot 2023-12-14 at 10 59 46 am

rio-tiler 6.2.3-post1
rasterio 1.3.9 but built with GDAL 3.8.1
GDAL 3.8.1 for the projection
OSX 14.1.2

@vincentsarago
Copy link
Member

@Plantain I wouldn't compare GDAL COG with rio-tiler but you can compare the output of gdalwarp command to read part of your file

import os
from rio_tiler.io import Reader


with Reader("http://static.skysight.io/rio-bug/orig.tiff") as src:
    img = src.tile(226, 162 ,8, tilesize=512, reproject_method="nearest", resampling_method="nearest")
    with open("226-162-8_RIOTILER.png", "wb") as f:
        f.write(img.render())

os.system("gdalwarp -of PNG -q /vsicurl/http://static.skysight.io/rio-bug/orig.tiff 226-162-8_GDAL.png -t_srs EPSG:3857 -ts 512 512 -te 15341217.324948 -5479006.187481 15497760.358876 -5322463.153553 -overwrite")

GDAL

226-162-8_GDAL

rio-tiler

226-162-8_RIOTILER

ahhhhhh this is because of #654 if you use 6.2.2 we get similar output

226-162-8_GDAL
226-162-8_RIOTILER

@vincentsarago
Copy link
Member

@Plantain I'm going to closes because it's related to #654

@Plantain
Copy link
Author

Plantain commented Dec 14, 2023 via email

@vincentsarago
Copy link
Member

#654 was only resolved in 6.2.7 so any version from 6.2.3 to 6.2.7 would have the same behaviour

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

No branches or pull requests

2 participants