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
Use ColorInterp or MaskFlags to check alpha band #51
Conversation
Hi @kn-id, thanks for opening this PR. While testing the code I couldn't find a dataset that was passing Do you mind sharing your image ? or at least the output of Thanks |
also seems @mojodna is using a slightly different test in marblecutter which might be worth to |
worth noting that
won't work but should be
I'm happy to update the function to something like:
but I'd love to make sure we understand why the first test (MaskFlags.alpha) didn't work for your image. |
Hi @vincentsarago, thanks for replying. Here's the output of rio info from my raster image: {
"blockxsize": 256,
"blockysize": 256,
"bounds": [
412620.45813000004,
9667517.052310001,
414303.85761000006,
9669577.69789
],
"colorinterp": [
"red",
"green",
"blue",
"alpha"
],
"compress": "lzw",
"count": 4,
"crs": "EPSG:32751",
"descriptions": [
null,
null,
null,
null
],
"driver": "GTiff",
"dtype": "uint8",
"height": 14721,
"indexes": [
1,
2,
3,
4
],
"interleave": "pixel",
"lnglat": [
122.22127123720861,
-2.998450073465773
],
"mask_flags": [
[
"nodata"
],
[
"nodata"
],
[
"nodata"
],
[
"nodata"
]
],
"nodata": null,
"res": [
0.13998000000000002,
0.13998000000000002
],
"shape": [
14721,
12026
],
"tiled": true,
"transform": [
0.13998000000000002,
0.0,
412620.45813000004,
0.0,
-0.13998000000000002,
9669577.69789,
0.0,
0.0,
1.0
],
"units": [
null,
null,
null,
null
],
"width": 12026
} And here's the link to my image https://drive.google.com/file/d/1pJdJ6sdNUQLrOPn4AZqaHoSN_zJrFihS/view?usp=sharing |
having |
It was created using pix4d. Any idea how to solve this? def has_alpha_band(src):
"""Check for alpha band or mask in source."""
if (
any([MaskFlags.alpha in flags for flags in src.mask_flag_enums])
or ColorInterp.alpha in src.colorinterp
):
return True
return False |
I have no objection to update the code with the proposed change |
Hi @vincentsarago, the code has been updated, please review this. Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 thanks @kn-id
@kn-id I'll add a test case for this new code and publish a new version of rio-tiler later today |
Hi @kn-id, I cannot create a file to test the new code (to add the test fixture). I tried to use |
@vincentsarago , I'm only able to get as small as 1,5 Mb. Here's the link https://drive.google.com/open?id=0Bzo9qLZh8_--c0RsS2l0WnBzbW1ya2RWZFlZNjFCZzZRUTRR |
thanks @kn-id, just release rio-tiler==1.0rc2 with the fix 🙏 |
I got this error: https://github.com/mapbox/rasterio/blob/master/rasterio/_warp.pyx#L907
and this code explains that it checks alpha band by GDAL color interpretation.
https://github.com/mapbox/rasterio/blob/master/rasterio/_warp.pyx#L898
p.s: sorry for my bad english