Skip to content
Snippets Groups Projects

Decoration button

Merged André Anjos requested to merge decoration-button into master
4 files
+ 110
27
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 66
15
@@ -37,7 +37,7 @@ Keyboard shortcuts
@@ -37,7 +37,7 @@ Keyboard shortcuts
object
object
``i | <Shift>-Zero | <Shift>-KP_Zero``
``i | <Shift>-Zero | <Shift>-KP_Zero``
inserts new point on a currently active object, before the current active
inserts new point on a currently active object, **before** the current active
point
point
``d | <Del>``
``d | <Del>``
@@ -68,6 +68,18 @@ Keyboard shortcuts
@@ -68,6 +68,18 @@ Keyboard shortcuts
``p``
``p``
moves to the previous image
moves to the previous image
 
``t``
 
turns-on keypoint decoration (lines or polygon depending on current mode)
 
 
``T``
 
turns-off keypoint decoration
 
 
``f``
 
turns-on image filtering
 
 
``F``
 
turns-off image filtering
 
``s``
``s``
saves current annotations
saves current annotations
@@ -203,7 +215,6 @@ class AnnotatorApp(tkinter.Tk):
@@ -203,7 +215,6 @@ class AnnotatorApp(tkinter.Tk):
# setup internal variables
# setup internal variables
self.curr_annotation = None #the currently annotated object
self.curr_annotation = None #the currently annotated object
self.annotation = [] #annotations existing on the current image
self.annotation = [] #annotations existing on the current image
self.filter = False
# builds the application interface - buttons, frames and the image canvas
# builds the application interface - buttons, frames and the image canvas
self.frames = {}
self.frames = {}
@@ -290,19 +301,29 @@ class AnnotatorApp(tkinter.Tk):
@@ -290,19 +301,29 @@ class AnnotatorApp(tkinter.Tk):
text='Displays the number of annotated points in the current ' \
text='Displays the number of annotated points in the current ' \
'object being annotated (highlit)')
'object being annotated (highlit)')
 
v = self.variables['decorations'] = tkinter.IntVar()
 
v.set(0)
 
b = self.buttons['decorations'] = tkinter.ttk.Checkbutton(f,
 
text="Decorations", variable=v, command=self.toggle_decorations)
 
b.grid(row=5, columnspan=2, sticky=tkinter.NSEW)
 
self.tooltips['decorations'] = widgets.Tooltip(b,
 
text='Shows line connectors or polygon fills depending on the ' \
 
'current drawing mode (keyboard: t/T - on/off)')
 
 
f = self.frames['filters'] = tkinter.ttk.LabelFrame(self.frames['left'],
f = self.frames['filters'] = tkinter.ttk.LabelFrame(self.frames['left'],
text="Filters")
text="Filters")
f.grid(row=2, sticky=tkinter.NSEW)
f.grid(row=2, sticky=tkinter.NSEW)
v = self.variables['adaheq'] = tkinter.IntVar()
v = self.variables['adaheq'] = tkinter.IntVar()
v.set(0)
v.set(0)
b = self.buttons['adaheq'] = tkinter.ttk.Checkbutton(f,
b = self.buttons['adaheq'] = tkinter.ttk.Checkbutton(f, text="CLAHE",
text="CLAHE", command=self.toggle_filter, variable=v)
variable=v, command=self.toggle_filter)
b.grid(row=0, columnspan=3, sticky=tkinter.W)
b.grid(row=0, columnspan=3, sticky=tkinter.W)
self.tooltips['adaheq'] = widgets.Tooltip(b,
self.tooltips['adaheq'] = widgets.Tooltip(b,
text='Applies Contrast Limited Adaptive Histogram Equalization ' \
text='Applies Contrast Limited Adaptive Histogram Equalization ' \
'(CLAHE) to the displayed image. You can finetune parameters ' \
'(CLAHE) to the displayed image. You can finetune parameters ' \
'on the text boxes below')
'on the text boxes below (keyboard: f/F - on/off)')
v = self.variables['adaheq-kernel-size'] = tkinter.IntVar()
v = self.variables['adaheq-kernel-size'] = tkinter.IntVar()
v.set(18)
v.set(18)
@@ -373,7 +394,7 @@ class AnnotatorApp(tkinter.Tk):
@@ -373,7 +394,7 @@ class AnnotatorApp(tkinter.Tk):
# setup filter function
# setup filter function
filter_function = None
filter_function = None
if self.filter:
if self.variables['adaheq'].get():
def _clahe(img, kernel, clip):
def _clahe(img, kernel, clip):
nimg = numpy.array(img)
nimg = numpy.array(img)
@@ -467,6 +488,12 @@ class AnnotatorApp(tkinter.Tk):
@@ -467,6 +488,12 @@ class AnnotatorApp(tkinter.Tk):
# sets the zoom level
# sets the zoom level
self.variables['zoom'].set('%g' % self.zoom)
self.variables['zoom'].set('%g' % self.zoom)
 
# if decorations are to be shown, set them
 
if self.variables['decorations'].get():
 
self.on_show_all()
 
else:
 
self.on_hide_all()
 
def save(self, *args, **kwargs):
def save(self, *args, **kwargs):
"""Action executed when we need to save the current annotations"""
"""Action executed when we need to save the current annotations"""
@@ -608,17 +635,28 @@ class AnnotatorApp(tkinter.Tk):
@@ -608,17 +635,28 @@ class AnnotatorApp(tkinter.Tk):
self.create_new_annotation() # adds a new base annotation object
self.create_new_annotation() # adds a new base annotation object
def on_show_all(self, event):
def toggle_decorations(self, *args):
 
"""Toggles current decoration status"""
 
 
if self.variables['decorations'].get():
 
self.on_show_all()
 
else:
 
self.on_hide_all()
 
 
 
def on_show_all(self, event=None):
"""Shows all elements"""
"""Shows all elements"""
logger.debug('Showing all...')
logger.debug('Showing all...')
 
self.variables['decorations'].set(1)
for k in self.annotation: k.show_decoration()
for k in self.annotation: k.show_decoration()
def on_hide_all(self, event):
def on_hide_all(self, event=None):
"""Hides all elements"""
"""Hides all elements"""
logger.debug('Hiding all...')
logger.debug('Hiding all...')
 
self.variables['decorations'].set(0)
for k in self.annotation: k.hide_decoration()
for k in self.annotation: k.hide_decoration()
@@ -680,15 +718,24 @@ class AnnotatorApp(tkinter.Tk):
@@ -680,15 +718,24 @@ class AnnotatorApp(tkinter.Tk):
self._update_status()
self._update_status()
def toggle_filter(self, event=None):
def toggle_filter(self, *args):
"""Togglers filter/no-filter on the displayed image"""
"""Togglers filter/no-filter on the displayed image"""
if self.filter:
self._rebuild_interface()
self.filter = False
self._rebuild_interface()
else:
def turn_filter_on(self, event=None):
self.filter = True
"""Turns filtering on"""
self._rebuild_interface()
 
self.variables['adaheq'].set(1)
 
self._rebuild_interface()
 
 
 
def turn_filter_off(self, event=None):
 
"""Turns filtering off"""
 
 
self.variables['adaheq'].set(0)
 
self._rebuild_interface()
def _add_bindings(self):
def _add_bindings(self):
@@ -713,6 +760,10 @@ class AnnotatorApp(tkinter.Tk):
@@ -713,6 +760,10 @@ class AnnotatorApp(tkinter.Tk):
self.bind("<Button-3>", self.remove_point_from_active_annotation)
self.bind("<Button-3>", self.remove_point_from_active_annotation)
self.bind("c", self.create_new_annotation)
self.bind("c", self.create_new_annotation)
 
self.bind("f", self.turn_filter_on)
 
self.bind("F", self.turn_filter_off)
 
self.bind("t", self.on_show_all)
 
self.bind("T", self.on_hide_all)
self.bind("o", self.activate_next_annotation)
self.bind("o", self.activate_next_annotation)
self.bind("O", self.activate_previous_annotation)
self.bind("O", self.activate_previous_annotation)
self.bind("m", self.toggle_active_annotation_mode)
self.bind("m", self.toggle_active_annotation_mode)
Loading