From a87a483b288abbefc2d670620d352ed02a88a0d1 Mon Sep 17 00:00:00 2001 From: sbamopoulos <62857539+sbamopoulos@users.noreply.github.com> Date: Sat, 27 Jun 2026 14:41:37 +0200 Subject: [PATCH] Fix shrink_labels for 1D face strips in 2D distributed segmentation. np.gradient on a 1D squeezed face returns a bare array, so np.linalg.norm(..., axis=0) became a scalar and zeroed every pixel. That broke tile-boundary stitching for 2D whole-slide runs without raising an error. Co-authored-by: Cursor --- cellpose/contrib/distributed_segmentation.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cellpose/contrib/distributed_segmentation.py b/cellpose/contrib/distributed_segmentation.py index a504670a..21c656d0 100644 --- a/cellpose/contrib/distributed_segmentation.py +++ b/cellpose/contrib/distributed_segmentation.py @@ -882,8 +882,12 @@ def block_face_adjacency_graph(faces, nlabels): def shrink_labels(plane, threshold): """Shrink labels in plane by some distance from their boundary""" - gradmag = np.linalg.norm(np.gradient(plane.squeeze()), axis=0) - shrunk_labels = np.copy(plane.squeeze()) + squeezed = plane.squeeze() + grads = np.gradient(squeezed) + if not isinstance(grads, tuple): + grads = (grads,) + gradmag = np.linalg.norm(grads, axis=0) + shrunk_labels = np.copy(squeezed) shrunk_labels[gradmag > 0] = 0 distances = scipy.ndimage.distance_transform_edt(shrunk_labels) shrunk_labels[distances <= threshold] = 0