glue-viz / glue

Linked Data Visualizations Across Multiple Files
http://glueviz.org
Other
721 stars 152 forks source link

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

Closed bmorris3 closed 2 months ago

bmorris3 commented 2 months ago

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 https://github.com/glue-viz/glue/pull/2468):

layer.composite._allow_bad_alpha = True