Commit 5723fa2be54ca74d5824b53743f452e9a673a49f
1 parent
1b21bd9e
Exists in
watershed
Marking the mask as edited when using watershed tool
Showing
3 changed files
with
18 additions
and
8 deletions
Show diff stats
invesalius/data/slice_.py
@@ -525,9 +525,7 @@ class Slice(object): | @@ -525,9 +525,7 @@ class Slice(object): | ||
525 | self.buffer_slices[orientation].vtk_image = image | 525 | self.buffer_slices[orientation].vtk_image = image |
526 | self.buffer_slices[orientation].vtk_mask = mask | 526 | self.buffer_slices[orientation].vtk_mask = mask |
527 | 527 | ||
528 | - print self.qblend | ||
529 | if self.qblend[orientation].get(slice_number, None) is not None: | 528 | if self.qblend[orientation].get(slice_number, None) is not None: |
530 | - print "BLENDING" | ||
531 | final_image = self.do_blend(final_image, | 529 | final_image = self.do_blend(final_image, |
532 | self.qblend[orientation][slice_number]) | 530 | self.qblend[orientation][slice_number]) |
533 | return final_image | 531 | return final_image |
invesalius/data/styles.py
@@ -30,7 +30,9 @@ import converters | @@ -30,7 +30,9 @@ import converters | ||
30 | import numpy as np | 30 | import numpy as np |
31 | 31 | ||
32 | from scipy import ndimage | 32 | from scipy import ndimage |
33 | +from scipy.misc import imsave | ||
33 | from skimage.morphology import watershed | 34 | from skimage.morphology import watershed |
35 | +from skimage import filter | ||
34 | 36 | ||
35 | ORIENTATIONS = { | 37 | ORIENTATIONS = { |
36 | "AXIAL": const.AXIAL, | 38 | "AXIAL": const.AXIAL, |
@@ -815,6 +817,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | @@ -815,6 +817,7 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | ||
815 | cvmask = do_colour_mask(vmask) | 817 | cvmask = do_colour_mask(vmask) |
816 | self.viewer.slice_.qblend[self.orientation][n] = cvmask | 818 | self.viewer.slice_.qblend[self.orientation][n] = cvmask |
817 | # TODO: To create a new function to reload images to viewer. | 819 | # TODO: To create a new function to reload images to viewer. |
820 | + viewer._flush_buffer = True | ||
818 | viewer.OnScrollBar() | 821 | viewer.OnScrollBar() |
819 | 822 | ||
820 | def OnBrushMove(self, obj, evt): | 823 | def OnBrushMove(self, obj, evt): |
@@ -898,16 +901,19 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | @@ -898,16 +901,19 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | ||
898 | if self.orientation == 'AXIAL': | 901 | if self.orientation == 'AXIAL': |
899 | image = self.viewer.slice_.matrix[n] | 902 | image = self.viewer.slice_.matrix[n] |
900 | mask = self.viewer.slice_.current_mask.matrix[n+1, 1:, 1:] | 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 | markers = self.matrix[n] | 905 | markers = self.matrix[n] |
902 | 906 | ||
903 | elif self.orientation == 'CORONAL': | 907 | elif self.orientation == 'CORONAL': |
904 | image = self.viewer.slice_.matrix[:, n, :] | 908 | image = self.viewer.slice_.matrix[:, n, :] |
905 | mask = self.viewer.slice_.current_mask.matrix[1:, n+1, 1:] | 909 | mask = self.viewer.slice_.current_mask.matrix[1:, n+1, 1:] |
910 | + self.viewer.slice_.current_mask.matrix[0, n+1, 0] | ||
906 | markers = self.matrix[:, n, :] | 911 | markers = self.matrix[:, n, :] |
907 | 912 | ||
908 | elif self.orientation == 'SAGITAL': | 913 | elif self.orientation == 'SAGITAL': |
909 | image = self.viewer.slice_.matrix[:, :, n] | 914 | image = self.viewer.slice_.matrix[:, :, n] |
910 | mask = self.viewer.slice_.current_mask.matrix[1: , 1:, n+1] | 915 | mask = self.viewer.slice_.current_mask.matrix[1: , 1:, n+1] |
916 | + self.viewer.slice_.current_mask.matrix[0 , 0, n+1] | ||
911 | markers = self.matrix[:, :, n] | 917 | markers = self.matrix[:, :, n] |
912 | 918 | ||
913 | 919 | ||
@@ -915,7 +921,8 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | @@ -915,7 +921,8 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | ||
915 | wl = self.viewer.slice_.window_level | 921 | wl = self.viewer.slice_.window_level |
916 | 922 | ||
917 | #tmp_image = get_LUT_value(image, ww, wl).astype('uint16') | 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 | print tmp_image.dtype, tmp_image.min(), tmp_image.max() | 926 | print tmp_image.dtype, tmp_image.min(), tmp_image.max() |
920 | tmp_mask = watershed(tmp_image, markers) | 927 | tmp_mask = watershed(tmp_image, markers) |
921 | 928 | ||
@@ -926,7 +933,9 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | @@ -926,7 +933,9 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | ||
926 | mask[(tmp_mask==2) & ((mask == 0) | (mask == 2) | (mask == 253))] = 2 | 933 | mask[(tmp_mask==2) & ((mask == 0) | (mask == 2) | (mask == 253))] = 2 |
927 | mask[(tmp_mask==1) & ((mask == 0) | (mask == 2) | (mask == 253))] = 253 | 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 | self.viewer.OnScrollBar(update3D=False) | 939 | self.viewer.OnScrollBar(update3D=False) |
931 | 940 | ||
932 | def get_coordinate_cursor(self): | 941 | def get_coordinate_cursor(self): |
@@ -1027,10 +1036,11 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | @@ -1027,10 +1036,11 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): | ||
1027 | tmp_mask = watershed(tmp_image, markers) | 1036 | tmp_mask = watershed(tmp_image, markers) |
1028 | 1037 | ||
1029 | mask[:] = 0 | 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 | self.viewer._flush_buffer = True | 1045 | self.viewer._flush_buffer = True |
1036 | self.viewer.slice_.discard_all_buffers() | 1046 | self.viewer.slice_.discard_all_buffers() |
invesalius/data/viewer_slice.py
@@ -283,6 +283,8 @@ class Viewer(wx.Panel): | @@ -283,6 +283,8 @@ class Viewer(wx.Panel): | ||
283 | if cleanup: | 283 | if cleanup: |
284 | self.style.CleanUp() | 284 | self.style.CleanUp() |
285 | 285 | ||
286 | + del self.style | ||
287 | + | ||
286 | style = styles.get_style(state)(self) | 288 | style = styles.get_style(state)(self) |
287 | 289 | ||
288 | setup = getattr(style, 'SetUp', None) | 290 | setup = getattr(style, 'SetUp', None) |