Commit 5723fa2be54ca74d5824b53743f452e9a673a49f

Authored by Thiago Franco de Moraes
1 parent 1b21bd9e
Exists in watershed

Marking the mask as edited when using watershed tool

invesalius/data/slice_.py
... ... @@ -525,9 +525,7 @@ class Slice(object):
525 525 self.buffer_slices[orientation].vtk_image = image
526 526 self.buffer_slices[orientation].vtk_mask = mask
527 527  
528   - print self.qblend
529 528 if self.qblend[orientation].get(slice_number, None) is not None:
530   - print "BLENDING"
531 529 final_image = self.do_blend(final_image,
532 530 self.qblend[orientation][slice_number])
533 531 return final_image
... ...
invesalius/data/styles.py
... ... @@ -30,7 +30,9 @@ import converters
30 30 import numpy as np
31 31  
32 32 from scipy import ndimage
  33 +from scipy.misc import imsave
33 34 from skimage.morphology import watershed
  35 +from skimage import filter
34 36  
35 37 ORIENTATIONS = {
36 38 "AXIAL": const.AXIAL,
... ... @@ -815,6 +817,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
815 817 cvmask = do_colour_mask(vmask)
816 818 self.viewer.slice_.qblend[self.orientation][n] = cvmask
817 819 # TODO: To create a new function to reload images to viewer.
  820 + viewer._flush_buffer = True
818 821 viewer.OnScrollBar()
819 822  
820 823 def OnBrushMove(self, obj, evt):
... ... @@ -898,16 +901,19 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
898 901 if self.orientation == 'AXIAL':
899 902 image = self.viewer.slice_.matrix[n]
900 903 mask = self.viewer.slice_.current_mask.matrix[n+1, 1:, 1:]
  904 + self.viewer.slice_.current_mask.matrix[n+1, 0, 0] = 1
901 905 markers = self.matrix[n]
902 906  
903 907 elif self.orientation == 'CORONAL':
904 908 image = self.viewer.slice_.matrix[:, n, :]
905 909 mask = self.viewer.slice_.current_mask.matrix[1:, n+1, 1:]
  910 + self.viewer.slice_.current_mask.matrix[0, n+1, 0]
906 911 markers = self.matrix[:, n, :]
907 912  
908 913 elif self.orientation == 'SAGITAL':
909 914 image = self.viewer.slice_.matrix[:, :, n]
910 915 mask = self.viewer.slice_.current_mask.matrix[1: , 1:, n+1]
  916 + self.viewer.slice_.current_mask.matrix[0 , 0, n+1]
911 917 markers = self.matrix[:, :, n]
912 918  
913 919  
... ... @@ -915,7 +921,8 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
915 921 wl = self.viewer.slice_.window_level
916 922  
917 923 #tmp_image = get_LUT_value(image, ww, wl).astype('uint16')
918   - tmp_image = ndimage.morphological_gradient(get_LUT_value(image, ww, wl).astype('uint16'), 5)
  924 + tmp_image = ndimage.morphological_gradient(get_LUT_value(image, ww, wl).astype('uint16'), 3)
  925 + imsave('/tmp/manolo.png', tmp_image)
919 926 print tmp_image.dtype, tmp_image.min(), tmp_image.max()
920 927 tmp_mask = watershed(tmp_image, markers)
921 928  
... ... @@ -926,7 +933,9 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
926 933 mask[(tmp_mask==2) & ((mask == 0) | (mask == 2) | (mask == 253))] = 2
927 934 mask[(tmp_mask==1) & ((mask == 0) | (mask == 2) | (mask == 253))] = 253
928 935  
929   - self.viewer._flush_buffer = True
  936 +
  937 + self.viewer.slice_.current_mask.was_edited = True
  938 + self.viewer._flush_buffer = False
930 939 self.viewer.OnScrollBar(update3D=False)
931 940  
932 941 def get_coordinate_cursor(self):
... ... @@ -1027,10 +1036,11 @@ class WaterShedInteractorStyle(DefaultInteractorStyle):
1027 1036 tmp_mask = watershed(tmp_image, markers)
1028 1037  
1029 1038 mask[:] = 0
1030   - mask[(tmp_mask==1)] = 253
1031   - mask[0] = 1
1032   - mask[:, 0, :] = 1
1033   - mask[:, :, 0] = 1
  1039 + mask[(tmp_mask == 1)] = 253
  1040 + #mask[:] = tmp_mask
  1041 + self.viewer.slice_.current_mask.matrix[0] = 1
  1042 + self.viewer.slice_.current_mask.matrix[:, 0, :] = 1
  1043 + self.viewer.slice_.current_mask.matrix[:, :, 0] = 1
1034 1044  
1035 1045 self.viewer._flush_buffer = True
1036 1046 self.viewer.slice_.discard_all_buffers()
... ...
invesalius/data/viewer_slice.py
... ... @@ -283,6 +283,8 @@ class Viewer(wx.Panel):
283 283 if cleanup:
284 284 self.style.CleanUp()
285 285  
  286 + del self.style
  287 +
286 288 style = styles.get_style(state)(self)
287 289  
288 290 setup = getattr(style, 'SetUp', None)
... ...