Skip to content

Commit 1efa142

Browse files
authored
Fix export (#169)
1 parent 8cc8fb0 commit 1efa142

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

synapse_net/imod/export.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,14 @@ def draw_spheres(
168168
radius = int(radius)
169169
mask = ball(radius)
170170
full_mask = np.zeros(shape, dtype="bool")
171-
full_slice = tuple(
172-
slice(max(co - radius, 0), min(co + radius, sh)) for co, sh in zip(coord, shape)
173-
)
174-
radius_clipped_left = [co - max(co - radius, 0) for co in coord]
175-
radius_clipped_right = [min(co + radius, sh) - co for co, sh in zip(coord, shape)]
176-
mask_slice = tuple(
177-
slice(radius + 1 - rl, radius + 1 + rr) for rl, rr in zip(radius_clipped_left, radius_clipped_right)
178-
)
171+
full_starts = [max(co - radius, 0) for co in coord]
172+
full_ends = [min(co + radius + 1, sh) for co, sh in zip(coord, shape)]
173+
if any(s >= e for s, e in zip(full_starts, full_ends)):
174+
continue
175+
full_slice = tuple(slice(s, e) for s, e in zip(full_starts, full_ends))
176+
ball_starts = [radius - (co - fs) for co, fs in zip(coord, full_starts)]
177+
ball_ends = [bs + (fe - fs) for bs, fe, fs in zip(ball_starts, full_ends, full_starts)]
178+
mask_slice = tuple(slice(s, e) for s, e in zip(ball_starts, ball_ends))
179179
full_mask[full_slice] = mask[mask_slice]
180180
labels[full_mask] = label_id
181181
return labels

0 commit comments

Comments
 (0)