Skip to content

Commit a87a483

Browse files
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 <cursoragent@cursor.com>
1 parent a54cb48 commit a87a483

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

cellpose/contrib/distributed_segmentation.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,8 +882,12 @@ def block_face_adjacency_graph(faces, nlabels):
882882

883883
def shrink_labels(plane, threshold):
884884
"""Shrink labels in plane by some distance from their boundary"""
885-
gradmag = np.linalg.norm(np.gradient(plane.squeeze()), axis=0)
886-
shrunk_labels = np.copy(plane.squeeze())
885+
squeezed = plane.squeeze()
886+
grads = np.gradient(squeezed)
887+
if not isinstance(grads, tuple):
888+
grads = (grads,)
889+
gradmag = np.linalg.norm(grads, axis=0)
890+
shrunk_labels = np.copy(squeezed)
887891
shrunk_labels[gradmag > 0] = 0
888892
distances = scipy.ndimage.distance_transform_edt(shrunk_labels)
889893
shrunk_labels[distances <= threshold] = 0

0 commit comments

Comments
 (0)