-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fixed gdal2tiles.py alpha channel handling #2299
Conversation
I encountered this problem while trying to process output from Pix4D. |
can you show the output of gdalinfo on input files that would require that patch ? |
Here is one such file:
|
I'm a bit skeptical about your change. On the file you exhibit, GetMaskBand() and GetBand(alpha_band_number) should both return Band 4 |
I could not check if |
Let me try to dump out the mask and the alpha band into separate files. |
==> band.GetBand() (maps to GDALGetBandNumber()) |
Both |
that's why I can't make sense of it. Are you sure you get different results with and without your patch on the very image you mentioned in #2299 (comment) and not on another one ? |
If you want, I could try to upload the file somewhere and link it but it's 6GB in size. |
Wait, there's one subtlety I overlooked. Your file has both nodata set (to -10000) and an alpha band (band 4). The GetMaskBand() logic would normally return a synthetic mask band based on the nodata value, but as -10000 is out of range for Byte data type, it goes on to select an alpha band. What you observed. But perhaps you've not instrumented all points, and there's some transformations within gdal2tiles that change the settings a bit.
Try to minimize it first with gdal_translate -outsize 1% 1% for example and see if you can still reproduce the issue |
I was able to reproduce the bug with the resized tif. |
I'm not all that familiar with the internals of gdal and it's entirely possible I'm overlooking something. |
gdal2tiles is confused by the invalid range of the nodata value. Try the following patch that will detect that
I'm wondering if a better/complementary fix wouldn't be for the GTiff driver to not report such non sensical nodata value to begin with (with a warning) |
…band data type (fixes issue raised in PR #2299)
I've committed the above patch in 9a16f92. Should fix the issue |
…band data type (fixes issue raised in PR #2299)
I have tested and this issue has been resolved by your commit (34f25f0). |
What does this PR do?
gdal2tiles.py by default prefers to use mask band over alpha band.
In certain edge cases, the mask indicates all data as valid and the alpha band contains the actual transparency information. This results in gdal2tiles.py creating output files with black regions.
This PR attempts to fix this case and force the use of an alpha band if it's present, otherwise, fall back to a mask band.
What are related issues/pull requests?
Tasklist
Environment
Unrelated
Any advice on how to implement tests would be appreciated.