From 5723fa2be54ca74d5824b53743f452e9a673a49f Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Thu, 12 Jun 2014 09:48:19 -0300 Subject: [PATCH] Marking the mask as edited when using watershed tool --- invesalius/data/slice_.py | 2 -- invesalius/data/styles.py | 22 ++++++++++++++++------ invesalius/data/viewer_slice.py | 2 ++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/invesalius/data/slice_.py b/invesalius/data/slice_.py index fec024c..2fa9731 100644 --- a/invesalius/data/slice_.py +++ b/invesalius/data/slice_.py @@ -525,9 +525,7 @@ class Slice(object): self.buffer_slices[orientation].vtk_image = image self.buffer_slices[orientation].vtk_mask = mask - print self.qblend if self.qblend[orientation].get(slice_number, None) is not None: - print "BLENDING" final_image = self.do_blend(final_image, self.qblend[orientation][slice_number]) return final_image diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py index c202d0c..a5bbf4f 100644 --- a/invesalius/data/styles.py +++ b/invesalius/data/styles.py @@ -30,7 +30,9 @@ import converters import numpy as np from scipy import ndimage +from scipy.misc import imsave from skimage.morphology import watershed +from skimage import filter ORIENTATIONS = { "AXIAL": const.AXIAL, @@ -815,6 +817,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): cvmask = do_colour_mask(vmask) self.viewer.slice_.qblend[self.orientation][n] = cvmask # TODO: To create a new function to reload images to viewer. + viewer._flush_buffer = True viewer.OnScrollBar() def OnBrushMove(self, obj, evt): @@ -898,16 +901,19 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): if self.orientation == 'AXIAL': image = self.viewer.slice_.matrix[n] mask = self.viewer.slice_.current_mask.matrix[n+1, 1:, 1:] + self.viewer.slice_.current_mask.matrix[n+1, 0, 0] = 1 markers = self.matrix[n] elif self.orientation == 'CORONAL': image = self.viewer.slice_.matrix[:, n, :] mask = self.viewer.slice_.current_mask.matrix[1:, n+1, 1:] + self.viewer.slice_.current_mask.matrix[0, n+1, 0] markers = self.matrix[:, n, :] elif self.orientation == 'SAGITAL': image = self.viewer.slice_.matrix[:, :, n] mask = self.viewer.slice_.current_mask.matrix[1: , 1:, n+1] + self.viewer.slice_.current_mask.matrix[0 , 0, n+1] markers = self.matrix[:, :, n] @@ -915,7 +921,8 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): wl = self.viewer.slice_.window_level #tmp_image = get_LUT_value(image, ww, wl).astype('uint16') - tmp_image = ndimage.morphological_gradient(get_LUT_value(image, ww, wl).astype('uint16'), 5) + tmp_image = ndimage.morphological_gradient(get_LUT_value(image, ww, wl).astype('uint16'), 3) + imsave('/tmp/manolo.png', tmp_image) print tmp_image.dtype, tmp_image.min(), tmp_image.max() tmp_mask = watershed(tmp_image, markers) @@ -926,7 +933,9 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): mask[(tmp_mask==2) & ((mask == 0) | (mask == 2) | (mask == 253))] = 2 mask[(tmp_mask==1) & ((mask == 0) | (mask == 2) | (mask == 253))] = 253 - self.viewer._flush_buffer = True + + self.viewer.slice_.current_mask.was_edited = True + self.viewer._flush_buffer = False self.viewer.OnScrollBar(update3D=False) def get_coordinate_cursor(self): @@ -1027,10 +1036,11 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): tmp_mask = watershed(tmp_image, markers) mask[:] = 0 - mask[(tmp_mask==1)] = 253 - mask[0] = 1 - mask[:, 0, :] = 1 - mask[:, :, 0] = 1 + mask[(tmp_mask == 1)] = 253 + #mask[:] = tmp_mask + self.viewer.slice_.current_mask.matrix[0] = 1 + self.viewer.slice_.current_mask.matrix[:, 0, :] = 1 + self.viewer.slice_.current_mask.matrix[:, :, 0] = 1 self.viewer._flush_buffer = True self.viewer.slice_.discard_all_buffers() diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index 951406f..3623674 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -283,6 +283,8 @@ class Viewer(wx.Panel): if cleanup: self.style.CleanUp() + del self.style + style = styles.get_style(state)(self) setup = getattr(style, 'SetUp', None) -- libgit2 0.21.2