Error adding mask as alpha channel
See original GitHub issueProblem
Calling array_to_image
using the array and mask returned from tile
using a 4 band tiff returns an error: WEBP driver doesn't support 5 bands. Must be 3 (RGB) or 4 (RGBA) bands.
Relevant code
# image at URL is 4 band geotiff
tile, mask = main.tile(url, int(tile_x), int(tile_y), int(tile_z), tilesize=256, nodata=None)
options = img_profiles["webp"]
buffer = utils.array_to_image(tile, mask=mask, img_format="webp", color_map=None, **options)
Possible Cause
It looks like utils:392 is just adding a band to the array without checking to see whether an alpha band already exists
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Save selections and alpha channel masks in Adobe Photoshop
Learn how to create and edit alpha channel masks, and save and load selections in Adobe Photoshop.
Read more >Mask from alpha channel is wrong - GIMP - GitLab - GNOME
right-click on the layer →Add Layer Mask.. → check Layer's alpha channel → add. Now you can already see, that the mask is...
Read more >Set Channel's alpha with masks does not work if set to same ...
The Set Channel effect does not seem to respect masks for the alpha source anymore, if the layer refers to itself.
Read more >Common Photoshop Masking Problem and Solution - Lenscraft
In case you're wondering why I'm talking about channels when this is a masking problem, it's because they are interchangeable with masks. Alpha...
Read more >Images can't contain alpha channels or transparencies
24 Answers 24 · Open the photo in Adobe Photoshop. · Under Layer menu, click Layer Mask and then From Transparency. · Delete...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@vincentsarago Yes we implemented additional check’s for 4 band images and handle them differently. I think the older version of
array_to_img
used ahas_alpha
check, was that specific to PIL support?👋 @a2hill sorry for this
bug
I don’t see a fix directly to thearray_to_image
function but to me it seems you could passindexes=(1,2,3)
to themain.tile
function and then the mask return should be the alpha band.Handling nodata/mask/alpha band is a tricky thing (I’ve worked on the matter all the week), maybe
utils.tile_read
could remove the alpha band from thedata
array directly ?Edits:
Here you are also passing the
mask
to the function, but the alpha band is already provided with your data, so you have two solution:indexes=(1,2,3)
mask
to theutils.array_to_image
function