Skip to content
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

Allow transparent regions in composite images when out of bounds #2482

Merged
merged 1 commit into from
Apr 17, 2024

Conversation

bmorris3
Copy link
Contributor

@bmorris3 bmorris3 commented Apr 16, 2024

Description

When multiple images are loaded in image viewers in glue, the fixed resolution buffer logic chooses the data layer color and alpha for out-of-bounds regions. The logic passes in a "data value" of negative infinity, and sends that through the colormap. By default, this can give black out-of-bounds regions, which darkens the appearance of lower layers. In a simple example with two layers below, both layers have alpha=0.5, but the larger and lower layer is darker because the upper layer is rendered on top with black pixels at alpha=0.5.

Screen Shot 2024-04-16 at 11 29 52

This PR replaces -np.inf with np.nan as the default out-of-bounds value to pass into the colormap. Because of the default nan/clipping in composite_array, users shouldn't see a difference in the viewer unless they opt-in, in which case they will see:

Screen Shot 2024-04-16 at 11 36 52

To opt in (after this PR), select a colormap with a transparent bad pixel:

import matplotlib.pyplot as plt
cmap = plt.cm.gray.with_extremes(bad=(0, 0, 0, 0))

and allow the bad alpha to be shown (since #2468):

layer.composite._allow_bad_alpha = True

Copy link
Member

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, thanks!

@astrofrog astrofrog merged commit 079829f into glue-viz:main Apr 17, 2024
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants