Skip to content

Commit

Permalink
fix: copy contour button with new lost obj contours
Browse files Browse the repository at this point in the history
  • Loading branch information
ElpadoCan committed Feb 3, 2025
1 parent 980eb65 commit 946fbe4
Showing 1 changed file with 43 additions and 23 deletions.
66 changes: 43 additions & 23 deletions cellacdc/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7637,7 +7637,8 @@ def gui_mousePressEventImg1(self, event):
isOnlyRightClick = (
right_click and canAnnotateDivision and not isAnnotateDivision
and not isMod and not is_right_click_action_ON
and not is_right_click_custom_ON and not copyContourON and not findNextMotherButtonON and not unknownLineageButtonON
and not is_right_click_custom_ON and not copyContourON
and not findNextMotherButtonON and not unknownLineageButtonON
)

if isOnlyRightClick:
Expand Down Expand Up @@ -7983,7 +7984,9 @@ def gui_mousePressEventImg1(self, event):
elif right_click and copyContourON:
hoverLostID = self.ax1_lostObjScatterItem.hoverLostID
lab2D = self.get_2Dlab(posData.lab)
lab2D[self.lostObjImage == hoverLostID] = hoverLostID
mask = self.lostObjImage == hoverLostID
lab2D[mask] = hoverLostID
self.lostObjImage[mask] = 0
self.set_2Dlab(lab2D)
self.update_rp()
self.updateAllImages()
Expand Down Expand Up @@ -11333,12 +11336,21 @@ def createDelROI(self, xl=None, yb=None, w=32, h=32, anchors=None):
return roi

def delROIstartedMoving(self, roi):
self.clearLostObjContoursItems()

def clearLostObjContoursItems(self):
self.ax1_lostObjScatterItem.setData([], [])
self.ax2_lostObjScatterItem.setData([], [])

self.ax1_lostTrackedScatterItem.setData([], [])
self.ax2_lostTrackedScatterItem.setData([], [])


self.ax2_lostObjImageItem.clear()
self.ax2_lostTrackedObjImageItem.clear()

self.ax1_lostObjImageItem.clear()
self.ax1_lostTrackedObjImageItem.clear()

def delROImoving(self, roi):
roi.setPen(color=(255,255,0))
# First bring back IDs if the ROI moved away
Expand Down Expand Up @@ -12660,10 +12672,9 @@ def copyLostObjContour_cb(self, checked):
self.ax1_lostObjScatterItem.hoverLostID = 0
if not checked:
return

self.lostObjImage = np.zeros_like(self.currentLab2D)
self.lostTrackedObjImage = np.zeros_like(self.currentLab2D)
self.addLostObjsToImage()
self.addTrackedLostObjsToImage()
self.updateLostContoursImage(0)

def lebelRoiTrangeCheckboxToggled(self, checked):
disabled = not checked
Expand Down Expand Up @@ -18937,8 +18948,8 @@ def checkScellsGone(self):

self.highlightNewIDs_ccaFailed(ScellsIDsGone, rp=prev_rp)
proceed = self.warnScellsGone(ScellsIDsGone, posData.frame_i)
self.ax1_lostObjScatterItem.setData([], [])
self.ax1_lostTrackedScatterItem.setData([], [])
self.clearLostObjContoursItems()

if not proceed:
return True, automaticallyDividedIDs

Expand Down Expand Up @@ -24529,6 +24540,10 @@ def updateLostContoursImage(self, ax, delROIsIDs=None):
continue

obj_contours = self.getObjContours(obj, all_external=True)

if ax == 0:
self.addLostObjsToImage(obj, lostID)

contours.extend(obj_contours)

self.drawLostObjContoursImage(imageItem, contours)
Expand Down Expand Up @@ -24601,16 +24616,6 @@ def getNearestLostObjID(self, y, x):

return nearest_ID

def addLostObjsToImage(self):
xx, yy = self.ax1_lostObjScatterItem.getData()
xx, yy = np.round(xx-0.5).astype(int), np.round(yy-0.5).astype(int)
labels = self.ax1_lostObjScatterItem.data['data']
self.lostObjImage[yy, xx] = labels
lostObjRp = skimage.measure.regionprops(self.lostObjImage)
for obj in lostObjRp:
filleObjMask = scipy.ndimage.binary_fill_holes(obj.image)
self.lostObjImage[obj.slice][filleObjMask] = obj.label

def setCcaIssueContour(self, obj):
objContours = self.getObjContours(obj, all_external=True)
for cont in objContours:
Expand Down Expand Up @@ -25113,7 +25118,7 @@ def highlightLostNew(self):
posData = self.data[self.pos_i]
delROIsIDs = self.getDelRoisIDs()

self.setAllContoursImages(delROIsIDs=delROIsIDs)
# self.setAllContoursImages(delROIsIDs=delROIsIDs)
if posData.frame_i == 0:
return

Expand All @@ -25128,9 +25133,14 @@ def highlightLostNew(self):
self.setAllLostObjContoursImage(delROIsIDs=delROIsIDs)
self.setAllLostTrackedObjContoursImage(delROIsIDs=delROIsIDs)

if self.copyContourButton.isChecked():
self.addLostObjsToImage()

def addLostObjsToImage(self, lostObj, lostID):
if not self.copyContourButton.isChecked():
return

obj_slice = self.getObjSlice(lostObj.slice)
obj_image = self.getObjImage(lostObj.image, lostObj.bbox)
self.lostObjImage[obj_slice][obj_image] = lostID

def highlightHoverLostObj(self, modifiers, event):
noModifier = modifiers == Qt.NoModifier
if not noModifier:
Expand All @@ -25142,13 +25152,23 @@ def highlightHoverLostObj(self, modifiers, event):
if event.isExit():
return

posData = self.data[self.pos_i]
x, y = event.pos()
xdata, ydata = int(x), int(y)
hoverLostID = self.lostObjImage[ydata, xdata]
self.ax1_lostObjScatterItem.hoverLostID = hoverLostID
self.ax1_lostObjScatterItem.hoverLostID = hoverLostID
if hoverLostID == 0:
self.ax1_lostObjScatterItem.setSize(self.contLineWeight+1)
self.ax1_lostObjScatterItem.setData([], [])
else:
prev_rp = posData.allData_li[posData.frame_i-1]['regionprops']
prev_IDs_idxs = posData.allData_li[posData.frame_i-1]['IDs_idxs']
lostObj = prev_rp[prev_IDs_idxs[hoverLostID]]
obj_contours = self.getObjContours(lostObj, all_external=True)
for cont in obj_contours:
xx = cont[:,0]
yy = cont[:,1]
self.ax1_lostObjScatterItem.addPoints(xx, yy)
self.ax1_lostObjScatterItem.setSize(self.contLineWeight+2)

def annotLostObjsToggled(self, checked):
Expand Down

0 comments on commit 946fbe4

Please sign in to comment.