Skip to content

Commit 9407fae

Browse files
timtreisclaude
andcommitted
Fix outline rendering to preserve data-driven colors when outline_color is None
Only apply uniform outline_color when explicitly set. When None (default), use the data-driven colors from label2rgb on the eroded ring — preserving the existing behavior for continuous/categorical outline coloring. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 342027c commit 9407fae

4 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/spatialdata_plot/pl/utils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,10 +1200,9 @@ def _map_color_seg(
12001200
if seg_erosionpx is not None:
12011201
val_im[val_im == erosion(val_im, footprint_rectangle((seg_erosionpx, seg_erosionpx)))] = 0
12021202

1203-
if seg_boundaries:
1204-
outline_rgba = colors.to_rgba(outline_color.get_hex_with_alpha() if outline_color is not None else "black")
1205-
1206-
# Build RGBA image: outline_color on the eroded ring, transparent elsewhere
1203+
if seg_boundaries and outline_color is not None:
1204+
# Uniform outline color requested: skip label2rgb, build RGBA directly
1205+
outline_rgba = colors.to_rgba(outline_color.get_hex_with_alpha())
12071206
outline_mask = val_im > 0
12081207
rgba = np.zeros((*val_im.shape, 4), dtype=float)
12091208
rgba[outline_mask, :3] = outline_rgba[:3]
@@ -1218,6 +1217,12 @@ def _map_color_seg(
12181217
image_alpha=0,
12191218
)
12201219

1220+
if seg_boundaries:
1221+
# Data-driven outline: use seg_im colors on the eroded ring, transparent elsewhere
1222+
outline_mask = val_im > 0
1223+
alpha_channel = outline_mask.astype(float)
1224+
return np.dstack((seg_im, alpha_channel))
1225+
12211226
if len(val_im.shape) != len(seg_im.shape):
12221227
val_im = np.expand_dims((val_im > 0).astype(int), axis=-1)
12231228
return np.dstack((seg_im, val_im))
7.94 KB
Loading
11.4 KB
Loading
1 KB
Loading

0 commit comments

Comments
 (0)