Skip to content

Commit

Permalink
Merge branch 'puisheelee-fix_stitch_threshold_bug'
Browse files Browse the repository at this point in the history
  • Loading branch information
carsen-stringer committed Jan 25, 2022
2 parents f1cb95b + d9ac0e2 commit 22c9562
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cellpose/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,20 @@ def get_masks_unet(output, cell_threshold=0, boundary_threshold=0):
def stitch3D(masks, stitch_threshold=0.25):
""" stitch 2D masks into 3D volume with stitch_threshold on IOU """
mmax = masks[0].max()
empty = 0

for i in range(len(masks)-1):
iou = metrics._intersection_over_union(masks[i+1], masks[i])[1:,1:]
if iou.size > 0:
if not iou.size and empty == 0:
masks[i+1] = masks[i+1]
mmax = masks[i+1].max()
elif not iou.size and not empty == 0:
icount = masks[i+1].max()
istitch = np.arange(mmax+1, mmax + icount+1, 1, int)
mmax += icount
istitch = np.append(np.array(0), istitch)
masks[i+1] = istitch[masks[i+1]]
else:
iou[iou < stitch_threshold] = 0.0
iou[iou < iou.max(axis=0)] = 0.0
istitch = iou.argmax(axis=1) + 1
Expand All @@ -369,6 +380,8 @@ def stitch3D(masks, stitch_threshold=0.25):
mmax += len(ino)
istitch = np.append(np.array(0), istitch)
masks[i+1] = istitch[masks[i+1]]
empty = 1

return masks

# merged diameter functions
Expand Down

0 comments on commit 22c9562

Please sign in to comment.