Commit eaec0d1b authored by Alessandro dos Santos Ferreira's avatar Alessandro dos Santos Ferreira
Browse files

Pynovisao - Otimizacoes e correcoes

parent f2621797
......@@ -49,10 +49,7 @@ class Image(object):
def toggle_toolbar(self):
self._toolbar_visible = not self._toolbar_visible
if self._toolbar_visible == True:
self._show_toolbar()
else:
self._hide_toolbar()
self._show_toolbar() if self._toolbar_visible else self._hide_toolbar()
def render(self, image, onclick = None):
......@@ -82,6 +79,7 @@ class Image(object):
if self._canvas is not None:
self.parent.image = image
self._im.set_data(self.parent.image)
self._fig.tight_layout()
self._canvas.draw()
......@@ -96,6 +94,12 @@ class Image(object):
if self._toolbar is not None:
self._toolbar.pack_forget()
self._toolbar.destroy()
# The command plt.clf() is used to minimize the effects of follow warning:
# "RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface
# (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory."
# However this part of code need to be refactored to prevent the memory leak!!!
plt.clf()
self._im = None
self._canvas = None
......
......@@ -54,6 +54,7 @@ if __name__ == "__main__":
tk.add_command("Choose segmenter", act.select_segmenter)
tk.add_command("Configure", act.config_segmenter, 'g')
tk.add_separator()
tk.add_command("Clean", act.clean_segmentation, 'l')
tk.add_command("Execute", act.run_segmenter, 'S')
tk.add_menu("Feature Extraction")
......
......@@ -106,7 +106,7 @@ class Act(object):
if self.tk.close_image():
self.tk.write_log("Closing image...")
self._const_image = None
self._image = None
def add_class(self, dialog = True, name = None, color = None):
n_classes = len(self.classes)
......@@ -216,13 +216,18 @@ class Act(object):
if self._const_image is None:
raise IException("Image not found")
self.tk.write_log("Running %s,,,", self.segmenter.get_name())
self.tk.write_log("Running %s...", self.segmenter.get_name())
self.tk.append_log("\nConfig: %s", str(self.segmenter.get_summary_config()))
self._image, run_time = self.segmenter.run(self._const_image)
self.tk.append_log("Time elapsed: %0.3f seconds", run_time)
self.tk.refresh_image(self._image)
def clean_segmentation(self):
if self._const_image is not None:
self.tk.write_log("Removing %s segmentation...", self.segmenter.get_name())
self.tk.refresh_image(self._const_image)
def select_extractors(self):
......
......@@ -23,6 +23,9 @@ class SkimageSegmenter(object):
__metaclass__ = ABCMeta
# flag FORCE_OPT highly increases speed of method paint_segment_skimage but performs a flawed painting
FORCE_OPT = False
def __init__(self, border_color = 'Yellow', border_outline = 'No'):
self.border_color = Config("Border Color", border_color, 'color')
self.border_outline = Config("Border Outline", border_outline, str)
......@@ -62,8 +65,7 @@ class SkimageSegmenter(object):
end_time = TimeUtils.get_time()
return segment, size_segment, idx_segment, (end_time - start_time)
def paint_segment_skimage(self, image, color, px = 0, py = 0, idx_segment = None, border = True, clear = False):
if self._segments is None:
return image, 0
......@@ -80,17 +82,18 @@ class SkimageSegmenter(object):
class_color = np.zeros((height,width,3), np.uint8)
class_color[:, :] = X11Colors.get_color(color)
if clear == False:
if SkimageSegmenter.FORCE_OPT == False:
colored_image = cv2.addWeighted(self._original_image, 0.7, class_color, 0.3, 0)
else:
colored_image = self._original_image
colored_image = cv2.addWeighted(image, 0.7, class_color, 0.3, 0)
colored_image = cv2.bitwise_and(colored_image, colored_image, mask=mask_segment)
new_image = cv2.bitwise_and(image, image, mask=mask_inv)
new_image = image if clear == False else self._original_image
new_image = cv2.bitwise_and(new_image, new_image, mask=mask_inv)
mask_segment[:] = 255
new_image = cv2.bitwise_or(new_image, colored_image, mask=mask_segment)
if border == True:
if border == True and SkimageSegmenter.FORCE_OPT == False:
color = X11Colors.get_color_zero_one(self.border_color.get_cast_val())
outline_color = color if self.border_outline.value == 'Yes' else None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment