question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cogeo create and erroneous values for certain 16bit datasets

See original GitHub issue

I’m opening this to document my findings, I’m not sure it’s even a problem with rio-cogeo per-se, it seems to go down all the way to rasterio (1.1.0) and perhaps GDAL (2.4.3).

Input (5 bands + alpha 16bit GeoTIFF): odm_orthophoto.zip

image

Band 1 Block=512x512 Type=UInt16, ColorInterp=Red
Band 2 Block=512x512 Type=UInt16, ColorInterp=Green
Band 3 Block=512x512 Type=UInt16, ColorInterp=Blue
Band 4 Block=512x512 Type=UInt16, ColorInterp=Gray
Band 5 Block=512x512 Type=UInt16, ColorInterp=Gray
Band 6 Block=512x512 Type=UInt16, ColorInterp=Alpha

Command:

rio cogeo create odm_orthophoto.tif out.tif

Output:

image

Band 1 Block=512x512 Type=UInt16, ColorInterp=Gray  Overviews: 1000x845, 500x423
Band 2 Block=512x512 Type=UInt16, ColorInterp=Undefined  Overviews: 1000x845, 500x423
Band 3 Block=512x512 Type=UInt16, ColorInterp=Undefined  Overviews: 1000x845, 500x423
Band 4 Block=512x512 Type=UInt16, ColorInterp=Undefined  Overviews: 1000x845, 500x423
Band 5 Block=512x512 Type=UInt16, ColorInterp=Undefined  Overviews: 1000x845, 500x423
Band 6 Block=512x512 Type=UInt16, ColorInterp=Undefined  Overviews: 1000x845, 500x423

Raster values seem to have been downscaled (?) or overflowed (?) in the process:

image

Alpha band is out of whack too, but I won’t worry about that for now.

I’ve narrowed this down to https://github.com/cogeotiff/rio-cogeo/blob/master/rio_cogeo/cogeo.py#L210. Once the WarpedVRT object is created, read operations on the virtual raster return erroneous values (they seem scaled down, eg. 24933 --> 97, which seems linear from 65535 to 255, but other values are still in the 65535 range, so it makes little sense). The data types are correct, although we’ve lost ColorInterp information (perhaps another problem).

This might be a problem with rasterio, or even GDAL? If I find a solution I will open a PR.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
vincentsaragocommented, Dec 20, 2019

you should use nodata instead of alpha when creating the file. Setting nodata value to 0 might have unexpected results when user provide an alpha band so I guess we should try to pursue this into GDAL/Rasterio to have a proper fix there

1reaction
vincentsaragocommented, Dec 19, 2019

thanks @pierotofy this is an interesting finding and yes might be a rasterio one, I’ll have a look!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To - rio-cogeo
From a command line point of view, it just means you need to add --co TILED=TRUE in a gdal_translate command. 1. Get some...
Read more >
Cloud Optimized GeoTIFF specification Engineering Report
This document is an OGC Public Engineering Report created as a ... The COG website at https://www.cogeo.org/ provides some help on how COG ......
Read more >
MSy - River Thames Conditions
Sports of the year 2012, Make a fishing rod rack, Thomas marzili medford? ... Team neophonic, Mastne vlasy v zime, Hymne du honduras,...
Read more >
The Swiss data cube, analysis ready data archive using earth ...
Given rapid environmental changes and the emergence of big data, ... The band is in unsigned 16-bit format, values are bit-packed and ...
Read more >
Visualizing and comparing population projection rasters
visual comparison of raster datasets have been developed using population projections as a case. To develop a tool able to enable such ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found