Skip to content

Fix shrink_labels for 1D face strips in 2D distributed segmentation#1480

Open
sbamopoulos wants to merge 1 commit into
MouseLand:mainfrom
sbamopoulos:fix/shrink-labels-2d-face-strips
Open

Fix shrink_labels for 1D face strips in 2D distributed segmentation#1480
sbamopoulos wants to merge 1 commit into
MouseLand:mainfrom
sbamopoulos:fix/shrink-labels-2d-face-strips

Conversation

@sbamopoulos

@sbamopoulos sbamopoulos commented Jun 27, 2026

Copy link
Copy Markdown

Summary

Fixes silent broken tile stitching for 2D distributed_eval runs (whole-slide / flat images).

Complements PR #1123 (merged in 4.2.1), which fixed the generate_binary_structure(3, 1) rank crash. This PR fixes the remaining bug in shrink_labels that zeroes all face pixels on 1D face strips.

Problem

During stitching, block_face_adjacency_graph calls shrink_labels on thin face arrays at tile boundaries.

Image type Typical face shape np.gradient returns np.linalg.norm(..., axis=0)
3D volume (1, H, W)(H,W) tuple of 2 arrays per-pixel (H,W)
2D WSI (1, W)(W,) single 1D array scalar

When gradmag is a scalar and non-zero, this line zeros every pixel:

shrunk_labels[gradmag > 0] = 0

Result: all faces are empty → no cross-tile label adjacency → masks are hard-cut at every tile boundary with no error raised.

@sbamopoulos sbamopoulos deleted the fix/shrink-labels-2d-face-strips branch June 27, 2026 12:18
@sbamopoulos sbamopoulos reopened this Jun 27, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant