Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions cellpose/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,15 +1202,23 @@ def merge_cells(self, idx):
for z in range(self.NZ):
ar0, ac0 = np.nonzero(self.cellpix[z] == self.prev_selected)
ar1, ac1 = np.nonzero(self.cellpix[z] == self.selected)
touching = np.logical_and((ar0[:, np.newaxis] - ar1) < 3,
(ac0[:, np.newaxis] - ac1) < 3).sum()
ar = np.hstack((ar0, ar1))
ac = np.hstack((ac0, ac1))
vr0, vc0 = np.nonzero(self.outpix[z] == self.prev_selected)
vr1, vc1 = np.nonzero(self.outpix[z] == self.selected)
cell0 = set(zip(ar0, ac0))
outline1 = set(zip(vr1, vc1))
#touching = cell0.intersection(outline1)
pixels0 = set(zip(ar0, ac0))
touching = any(
(r0, c0) in pixels0
for r1, c1 in zip(ar1, ac1)
for r0 in range(r1 - 2, r1 + 3)
for c0 in range(c1 - 2, c1 + 3)
)
self.outpix[z, vr0, vc0] = 0
self.outpix[z, vr1, vc1] = 0
if touching > 0:
if touching:
mask = np.zeros((np.ptp(ar) + 4, np.ptp(ac) + 4), np.uint8)
mask[ar - ar.min() + 2, ac - ac.min() + 2] = 1
contours = cv2.findContours(mask, cv2.RETR_EXTERNAL,
Expand Down