cogeotiff / rio-tiler

User friendly Rasterio plugin to read raster datasets.
https://cogeotiff.github.io/rio-tiler/
BSD 3-Clause "New" or "Revised" License
502 stars 106 forks source link

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

Closed Plantain closed 8 months ago

Plantain commented 8 months ago

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 commented 8 months ago

@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 commented 8 months ago

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

Plantain commented 8 months ago

This was with 6.2.3post1, which I think is not affected by that issue? I think it's even worse again post 6.2.4, I will generate another sample from that.

On Thu, 14 Dec 2023, 6:01 pm Vincent Sarago, @.***> wrote:

Closed #662 https://github.com/cogeotiff/rio-tiler/issues/662 as completed.

— Reply to this email directly, view it on GitHub https://github.com/cogeotiff/rio-tiler/issues/662#event-11244760796, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACODF7Y4DNG5M4J7XR2LU3YJKW3XAVCNFSM6AAAAABAUBJ2P2VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJRGI2DINZWGA3TSNQ . You are receiving this because you were mentioned.Message ID: @.***>

vincentsarago commented 8 months ago

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