Commit 07491a648f2a4258bfc7ffd09fff316d5ee161bb
1 parent
dfd1d8a2
Exists in
watershed_improvements_bkp
Not applying border detection (gradient) when using watershed ift
Showing
1 changed file
with
46 additions
and
19 deletions
Show diff stats
invesalius/data/styles.py
... | ... | @@ -1065,19 +1065,35 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): |
1065 | 1065 | wl = self.viewer.slice_.window_level |
1066 | 1066 | |
1067 | 1067 | if BRUSH_BACKGROUND in markers and BRUSH_FOREGROUND in markers: |
1068 | - w_algorithm = WALGORITHM[self.config.algorithm] | |
1068 | + #w_algorithm = WALGORITHM[self.config.algorithm] | |
1069 | 1069 | bstruct = generate_binary_structure(2, CON2D[self.config.con_2d]) |
1070 | 1070 | if self.config.use_ww_wl: |
1071 | - tmp_image = ndimage.morphological_gradient( | |
1072 | - get_LUT_value(image, ww, wl).astype('uint16'), | |
1073 | - self.config.mg_size) | |
1074 | - #tmp_image = get_LUT_value(image, ww, wl).astype('uint16') | |
1071 | + if self.config.algorithm == 'Watershed': | |
1072 | + tmp_image = ndimage.morphological_gradient( | |
1073 | + get_LUT_value(image, ww, wl).astype('uint16'), | |
1074 | + self.config.mg_size) | |
1075 | + tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) | |
1076 | + else: | |
1077 | + #tmp_image = ndimage.gaussian_filter(get_LUT_value(image, ww, wl).astype('uint16'), self.config.mg_size) | |
1078 | + #tmp_image = ndimage.morphological_gradient( | |
1079 | + #get_LUT_value(image, ww, wl).astype('uint16'), | |
1080 | + #self.config.mg_size) | |
1081 | + tmp_image = get_LUT_value(image, ww, wl).astype('uint16') | |
1082 | + #markers[markers == 2] = -1 | |
1083 | + tmp_mask = watershed_ift(tmp_image, markers.astype('int16'), bstruct) | |
1084 | + #markers[markers == -1] = 2 | |
1085 | + #tmp_mask[tmp_mask == -1] = 2 | |
1075 | 1086 | |
1076 | - tmp_mask = w_algorithm(tmp_image, markers.astype('int16'), bstruct) | |
1077 | 1087 | else: |
1078 | - tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) | |
1079 | - #tmp_image = (image - image.min()).astype('uint16') | |
1080 | - tmp_mask = w_algorithm(tmp_image, markers.astype('int16'), bstruct) | |
1088 | + if self.config.algorithm == 'Watershed': | |
1089 | + tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) | |
1090 | + tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) | |
1091 | + else: | |
1092 | + #tmp_image = (image - image.min()).astype('uint16') | |
1093 | + #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size) | |
1094 | + #tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) | |
1095 | + tmp_image = image - image.min().astype('uint16') | |
1096 | + tmp_mask = watershed_ift(tmp_image, markers.astype('int16'), bstruct) | |
1081 | 1097 | |
1082 | 1098 | if self.viewer.overwrite_mask: |
1083 | 1099 | mask[:] = 0 |
... | ... | @@ -1183,19 +1199,30 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): |
1183 | 1199 | ww = self.viewer.slice_.window_width |
1184 | 1200 | wl = self.viewer.slice_.window_level |
1185 | 1201 | if BRUSH_BACKGROUND in markers and BRUSH_FOREGROUND in markers: |
1186 | - w_algorithm = WALGORITHM[self.config.algorithm] | |
1202 | + #w_algorithm = WALGORITHM[self.config.algorithm] | |
1187 | 1203 | bstruct = generate_binary_structure(3, CON3D[self.config.con_3d]) |
1188 | - print bstruct | |
1189 | 1204 | if self.config.use_ww_wl: |
1190 | - tmp_image = ndimage.morphological_gradient( | |
1191 | - get_LUT_value(image, ww, wl).astype('uint16'), | |
1192 | - self.config.mg_size) | |
1193 | - #tmp_image = get_LUT_value(image, ww, wl).astype('uint16') | |
1194 | - tmp_mask = w_algorithm(tmp_image, markers.astype('int16'), bstruct) | |
1205 | + if self.config.algorithm == 'Watershed': | |
1206 | + tmp_image = ndimage.morphological_gradient( | |
1207 | + get_LUT_value(image, ww, wl).astype('uint16'), | |
1208 | + self.config.mg_size) | |
1209 | + tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) | |
1210 | + else: | |
1211 | + tmp_image = get_LUT_value(image, ww, wl).astype('uint16') | |
1212 | + #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size) | |
1213 | + #tmp_image = ndimage.morphological_gradient( | |
1214 | + #get_LUT_value(image, ww, wl).astype('uint16'), | |
1215 | + #self.config.mg_size) | |
1216 | + tmp_mask = watershed_ift(tmp_image, markers.astype('int16'), bstruct) | |
1195 | 1217 | else: |
1196 | - tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) | |
1197 | - #tmp_image = (image - image.min()).astype('uint16') | |
1198 | - tmp_mask = w_algorithm(tmp_image, markers.astype('int16'), bstruct) | |
1218 | + if self.config.algorithm == 'Watershed': | |
1219 | + tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) | |
1220 | + tmp_mask = watershed(tmp_image, markers.astype('int16'), bstruct) | |
1221 | + else: | |
1222 | + tmp_image = (image - image.min()).astype('uint16') | |
1223 | + #tmp_image = ndimage.gaussian_filter(tmp_image, self.config.mg_size) | |
1224 | + #tmp_image = ndimage.morphological_gradient((image - image.min()).astype('uint16'), self.config.mg_size) | |
1225 | + tmp_mask = watershed_ift(tmp_image, markers.astype('int8'), bstruct) | |
1199 | 1226 | |
1200 | 1227 | if self.viewer.overwrite_mask: |
1201 | 1228 | mask[:] = 0 | ... | ... |