Skip to content

Commit 962b831

Browse files
MeyerBendertimtreis
authored andcommitted
removed spillover from the fill color when plotting only the outlines of the labels
1 parent d7c416c commit 962b831

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/spatialdata_plot/pl/render.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ def _render_labels(
13491349
assert color_source_vector is None
13501350

13511351
def _draw_labels(seg_erosionpx: int | None, seg_boundaries: bool, alpha: float,
1352-
outline_color: ColorLike | tuple[ColorLike] | None = None) -> matplotlib.image.AxesImage:
1352+
outline_color = None) -> matplotlib.image.AxesImage:
13531353
labels = _map_color_seg(
13541354
seg=label.values,
13551355
cell_id=instance_id,

src/spatialdata_plot/pl/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
from scipy.spatial import ConvexHull
5656
from shapely.errors import GEOSException
5757
from skimage.color import label2rgb
58-
from skimage.morphology import erosion, square
58+
from skimage.morphology import erosion, footprint_rectangle
5959
from skimage.segmentation import find_boundaries
6060
from skimage.util import map_array
6161
from spatialdata import (
@@ -1200,7 +1200,7 @@ def _map_color_seg(
12001200
cols = cmap_params.cmap(cmap_params.norm(color_vector))
12011201

12021202
if seg_erosionpx is not None:
1203-
val_im[val_im == erosion(val_im, square(seg_erosionpx))] = 0
1203+
val_im[val_im == erosion(val_im, footprint_rectangle((seg_erosionpx, seg_erosionpx)))] = 0
12041204

12051205
seg_im: ArrayLike = label2rgb(
12061206
label=val_im,
@@ -1215,7 +1215,7 @@ def _map_color_seg(
12151215
seg = np.squeeze(seg, axis=0)
12161216

12171217
# Binary boundary mask
1218-
boundary_mask = find_boundaries(seg) # True where boundaries are
1218+
boundary_mask = seg.astype(bool)
12191219

12201220
# Ensure seg_im is float in 0-1 and has 3 channels
12211221
seg_float = seg_im.astype(float)
@@ -1234,11 +1234,11 @@ def _map_color_seg(
12341234
else:
12351235
# assume it's your Color object
12361236
outline_rgba = mcolors.to_rgba(outline_color.get_hex_with_alpha())
1237-
1237+
12381238
# Apply outline color to boundary pixels, but keep original alpha from val_im
12391239
seg_float[boundary_mask, :3] = outline_rgba[:3] # RGB
12401240
seg_float[boundary_mask, 3] = alpha_channel[boundary_mask] * outline_rgba[3] # scale alpha
1241-
1241+
12421242
return seg_float # H x W x 4, valid RGBA
12431243

12441244
if len(val_im.shape) != len(seg_im.shape):

0 commit comments

Comments
 (0)