diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py index bd937a0..4508e6f 100644 --- a/invesalius/data/styles.py +++ b/invesalius/data/styles.py @@ -1065,19 +1065,35 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): wl = self.viewer.slice_.window_level if BRUSH_BACKGROUND in markers and BRUSH_FOREGROUND in markers: - w_algorithm = WALGORITHM[self.config.algorithm] + #w_algorithm = WALGORITHM[self.config.algorithm] bstruct = generate_binary_structure(2, CON2D[self.config.con_2d]) if self.config.use_ww_wl: - tmp_image = ndimage.morphological_gradient( - get_LUT_value(image, ww, wl).astype('uint16'), - self.config.mg_size) - #tmp_image = get_LUT_value(image, ww, wl).astype('uint16') + if self.config.algorithm == 'Watershed': + tmp_image = ndimage.morphological_gradient( + get_LUT_value(image, ww, wl).astype('uint16'), + self.config.mg_size) + tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) + else: + #tmp_image = ndimage.gaussian_filter(get_LUT_value(image, ww, wl).astype('uint16'), self.config.mg_size) + #tmp_image = ndimage.morphological_gradient( + #get_LUT_value(image, ww, wl).astype('uint16'), + #self.config.mg_size) + tmp_image = get_LUT_value(image, ww, wl).astype('uint16') + #markers[markers == 2] = -1 + tmp_mask = watershed_ift(tmp_image, markers.astype('int16'), bstruct) + #markers[markers == -1] = 2 + #tmp_mask[tmp_mask == -1] = 2 - tmp_mask = w_algorithm(tmp_image, markers.astype('int16'), bstruct) else: - tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) - #tmp_image = (image - image.min()).astype('uint16') - tmp_mask = w_algorithm(tmp_image, markers.astype('int16'), bstruct) + if self.config.algorithm == 'Watershed': + tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) + tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) + else: + #tmp_image = (image - image.min()).astype('uint16') + #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size) + #tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) + tmp_image = image - image.min().astype('uint16') + tmp_mask = watershed_ift(tmp_image, markers.astype('int16'), bstruct) if self.viewer.overwrite_mask: mask[:] = 0 @@ -1183,19 +1199,30 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): ww = self.viewer.slice_.window_width wl = self.viewer.slice_.window_level if BRUSH_BACKGROUND in markers and BRUSH_FOREGROUND in markers: - w_algorithm = WALGORITHM[self.config.algorithm] + #w_algorithm = WALGORITHM[self.config.algorithm] bstruct = generate_binary_structure(3, CON3D[self.config.con_3d]) - print bstruct if self.config.use_ww_wl: - tmp_image = ndimage.morphological_gradient( - get_LUT_value(image, ww, wl).astype('uint16'), - self.config.mg_size) - #tmp_image = get_LUT_value(image, ww, wl).astype('uint16') - tmp_mask = w_algorithm(tmp_image, markers.astype('int16'), bstruct) + if self.config.algorithm == 'Watershed': + tmp_image = ndimage.morphological_gradient( + get_LUT_value(image, ww, wl).astype('uint16'), + self.config.mg_size) + tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) + else: + tmp_image = get_LUT_value(image, ww, wl).astype('uint16') + #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size) + #tmp_image = ndimage.morphological_gradient( + #get_LUT_value(image, ww, wl).astype('uint16'), + #self.config.mg_size) + tmp_mask = watershed_ift(tmp_image, markers.astype('int16'), bstruct) else: - tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) - #tmp_image = (image - image.min()).astype('uint16') - tmp_mask = w_algorithm(tmp_image, markers.astype('int16'), bstruct) + if self.config.algorithm == 'Watershed': + tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) + tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) + else: + tmp_image = (image - image.min()).astype('uint16') + #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size) + #tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) + tmp_mask = watershed_ift(tmp_image, markers.astype('int8'), bstruct) if self.viewer.overwrite_mask: mask[:] = 0 -- libgit2 0.21.2