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.

Error adding mask as alpha channel

See original GitHub issue

Problem

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:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
a2hillcommented, Feb 18, 2019

@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 a has_alpha check, was that specific to PIL support?

1reaction
vincentsaragocommented, Feb 16, 2019

👋 @a2hill sorry for this bug I don’t see a fix directly to the array_to_image function but to me it seems you could pass indexes=(1,2,3) to the main.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 the data array directly ?

Edits:

buffer = utils.array_to_image(tile, mask=mask, img_format=“webp”, color_map=None, **options)

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:

  • uses indexes=(1,2,3)
  • don’t pass mask to the utils.array_to_image function
Read more comments on GitHub >

github_iconTop 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 >

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