Skip to content

Commit

Permalink
add label erosion/dilation to trk files
Browse files Browse the repository at this point in the history
Same keybinds as in npzs
  • Loading branch information
geneva-miller committed Jul 11, 2020
1 parent 75192ba commit 93d05ef
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions desktop/caliban.py
Original file line number Diff line number Diff line change
Expand Up @@ -2585,6 +2585,10 @@ def label_mode_single_keypress_helper(self, symbol, modifiers):
if symbol == key.X:
self.mode.update("QUESTION", action="DELETE", **self.mode.info)

# CHANGE SIZE INCREMENTALLY
if symbol == key.Y:
self.mode.update("QUESTION", action="EROSION DILATION", **self.mode.info)

def label_mode_multiple_keypress_helper(self, symbol, modifiers):
'''
Helper function for keypress handling. The keybinds that are
Expand Down Expand Up @@ -2687,6 +2691,15 @@ def label_mode_question_keypress_helper(self, symbol, modifiers):
self.action_parent()
self.mode.clear()

# RESPOND TO MORPHOLOGICAL EROSION OR DILATION QUESTION
elif self.mode.action == "EROSION DILATION":
if symbol == key.Y:
self.action_dilate_label()
self.mode.clear()
elif symbol == key.T:
self.action_erode_label()
self.mode.clear()

def custom_prompt(self):
if self.mode.kind == "QUESTION":
if self.mode.action == "REPLACE":
Expand Down Expand Up @@ -3038,6 +3051,50 @@ def action_trim_pixels(self):

self.update_image = True

def action_erode_label(self):
'''
Use morphological erosion to incrementally shrink the selected label.
'''

frame = self.mode.frame
label = self.mode.label
img_ann = self.tracked[frame,:,:,0]

# if label is adjacent to another label, don't let that interfere
img_erode = np.where(img_ann==label, label, 0)
# erode the label
img_erode = erosion(img_erode, square(3))

# put the label back in
img_ann = np.where(img_ann==label, img_erode, img_ann)

in_modified = np.any(np.isin(img_ann, label))
if not in_modified:
self.del_cell_info(del_label = label, frame = frame)

self.tracked[frame,:,:,0] = img_ann

self.update_image = True

def action_dilate_label(self):
'''
Use morphological dilation to incrementally increase the selected label.
Does not overwrite bordering labels.
'''

frame = self.mode.frame
label = self.mode.label
img_ann = self.tracked[frame,:,:,0]

img_dilate = np.where(img_ann==label, label, 0)
img_dilate = dilation(img_dilate, square(3))

img_ann = np.where(np.logical_and(img_dilate==label, img_ann==0), img_dilate, img_ann)

self.tracked[frame,:,:,0] = img_ann

self.update_image = True

def add_cell_info(self, add_label, frame):
'''
helper function for actions that add a cell to the trk
Expand Down

0 comments on commit 93d05ef

Please sign in to comment.