Skip to content

Commit

Permalink
Merge pull request #58 from sagar87/fix/background_color
Browse files Browse the repository at this point in the history
added support for background color when rendering multiple channels
  • Loading branch information
MeyerBender authored Jun 18, 2024
2 parents ac1586e + 5666916 commit e4dba67
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion spatialproteomics/pl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from skimage.morphology import closing, square
from skimage.segmentation import clear_border, find_boundaries

from ..base_logger import logger
from ..pp.utils import _normalize


Expand All @@ -26,7 +27,17 @@ def _get_linear_colormap(palette: list, background: str = "black"):
list
A list of LinearSegmentedColormap objects.
"""
return [LinearSegmentedColormap.from_list(color, [background, color], N=256) for color in palette]
# if there are multiple colors in the palette, we only want to set the background color for the first colormap
out = []
if len(palette) > 1 and background == "white":
logger.warning(
"Setting the background color to white for multiple colors in the palette is currently not recommended, as only the first marker will be visible."
)

for i, color in enumerate(palette):
bg = background if i == 0 else (0, 0, 0, 0) # transparent background for all but the first rgba layer
out.append(LinearSegmentedColormap.from_list(color, [bg, color], N=256))
return out


def _get_listed_colormap(palette: dict):
Expand Down

0 comments on commit e4dba67

Please sign in to comment.