From bb286f6d662fea7a86ff4d898d0f9506da9b01ae Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Thu, 1 Sep 2016 13:54:28 -0300 Subject: [PATCH] Segmetation dynamic --- invesalius/data/styles.py | 24 ++++++++++++++++++++---- invesalius/gui/dialogs.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 83 insertions(+), 24 deletions(-) diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py index ae7d18a..a69e54a 100644 --- a/invesalius/data/styles.py +++ b/invesalius/data/styles.py @@ -1854,6 +1854,11 @@ class FFillSegmentationConfig(object): self.fill_value = 254 + self.method = 'threshold' + + self.dev_min = 50 + self.dev_max = 50 + class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): def __init__(self, viewer): @@ -1898,9 +1903,20 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): mask = self.viewer.slice_.current_mask.matrix[1:, 1:, 1:] image = self.viewer.slice_.matrix - print image[z, y, x] + v = image[z, y, x] + print v + + if self.config.method == 'threshold': + t0 = self.config.t0 + t1 = self.config.t1 + elif self.config.method == 'dynamic': + print 'Method dynamic' + t0 = v - self.config.dev_min + t1 = v + self.config.dev_max + + print v, t0, t1 - if image[z, y, x] < self.config.t0 or image[z, y, x] > self.config.t1: + if image[z, y, x] < t0 or image[z, y, x] > t1: return if self.config.target == "3D": @@ -1920,7 +1936,7 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): bstruct[:, :, 0] = _bstruct if self.config.target == '2D': - floodfill.floodfill_threshold(image, [[x, y, z]], self.config.t0, self.config.t1, self.config.fill_value, bstruct, mask) + floodfill.floodfill_threshold(image, [[x, y, z]], t0, t1, self.config.fill_value, bstruct, mask) b_mask = self.viewer.slice_.buffer_slices[self.orientation].mask index = self.viewer.slice_.buffer_slices[self.orientation].index @@ -1934,7 +1950,7 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): self.viewer.slice_.current_mask.save_history(index, self.orientation, p_mask, b_mask) else: with futures.ThreadPoolExecutor(max_workers=1) as executor: - future = executor.submit(floodfill.floodfill_threshold, image, [[x, y, z]], self.config.t0, self.config.t1, self.config.fill_value, bstruct, mask) + future = executor.submit(floodfill.floodfill_threshold, image, [[x, y, z]], t0, t1, self.config.fill_value, bstruct, mask) dlg = wx.ProgressDialog(self._progr_title, self._progr_msg, parent=None, style=wx.PD_APP_MODAL) while not future.done(): diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index 81183e4..8e471f4 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -2086,32 +2086,63 @@ class FFillSegmentationOptionsDialog(wx.Dialog): self.threshold = grad.GradientCtrl(self, -1, int(bound_min), int(bound_max), self.config.t0, self.config.t1, colour) + self.threshold.SetMinSize((250, -1)) + + self.method_threshold = wx.RadioButton(self, -1, _(u"Threshold"), style=wx.RB_GROUP) + self.method_dynamic = wx.RadioButton(self, -1, _(u"Dynamic")) + + if self.config.method == 'dynamic': + self.method_dynamic.SetValue(1) + else: + self.method_threshold.SetValue(1) + self.config.method = 'threshold' + + self.deviation_min = wx.SpinCtrl(self, -1, value='%d' % self.config.dev_min, min=0, max=10000) + self.deviation_max = wx.SpinCtrl(self, -1, value='%d' % self.config.dev_max, min=0, max=10000) # Sizer - sizer = wx.GridBagSizer(15, 6) - sizer.AddStretchSpacer((0, 0)) + sizer = wx.BoxSizer(wx.VERTICAL) - sizer.Add(wx.StaticText(self, -1, _(u"Parameters")), (1, 0), (1, 6), flag=wx.LEFT, border=7) - sizer.Add(self.target_2d, (2, 0), (1, 6), flag=wx.LEFT, border=9) - sizer.Add(self.target_3d, (3, 0), (1, 6), flag=wx.LEFT, border=9) + sizer.AddSpacer(7) - sizer.AddStretchSpacer((4, 0)) + sizer.Add(wx.StaticText(self, -1, _(u"Parameters")), flag=wx.LEFT, border=7) + sizer.AddSpacer(5) + sizer.Add(self.target_2d, flag=wx.LEFT, border=9) + sizer.Add(self.target_3d, flag=wx.LEFT, border=9) - sizer.Add(wx.StaticText(self, -1, _(u"2D Connectivity")), (5, 0), (1, 6), flag=wx.LEFT, border=9) - sizer.Add(self.conect2D_4, (6, 0), flag=wx.LEFT, border=9) - sizer.Add(self.conect2D_8, (6, 1), flag=wx.LEFT, border=9) + sizer.AddSpacer(7) - sizer.AddStretchSpacer((7, 0)) + sizer.Add(wx.StaticText(self, -1, _(u"2D Connectivity")), flag=wx.LEFT, border=9) + sizer.AddSpacer(5) + sizer_2d = wx.BoxSizer(wx.HORIZONTAL) + sizer_2d.Add(self.conect2D_4, flag=wx.LEFT, border=11) + sizer_2d.Add(self.conect2D_8, flag=wx.LEFT, border=11) + sizer.Add(sizer_2d) - sizer.Add(wx.StaticText(self, -1, _(u"3D Connectivity")), (8, 0), (1, 6), flag=wx.LEFT, border=9) - sizer.Add(self.conect3D_6, (9, 0), flag=wx.LEFT, border=9) - sizer.Add(self.conect3D_18, (9, 1), flag=wx.LEFT, border=9) - sizer.Add(self.conect3D_26, (9, 2), flag=wx.LEFT, border=9) - sizer.AddStretchSpacer((10, 0)) + sizer.AddSpacer(7) + + sizer.Add(wx.StaticText(self, -1, _(u"3D Connectivity")), flag=wx.LEFT, border=9) + sizer.AddSpacer(5) + sizer_3d = wx.BoxSizer(wx.HORIZONTAL) + sizer_3d.Add(self.conect3D_6, flag=wx.LEFT, border=11) + sizer_3d.Add(self.conect3D_18, flag=wx.LEFT, border=11) + sizer_3d.Add(self.conect3D_26, flag=wx.LEFT, border=11) + sizer.Add(sizer_3d) + + sizer.AddSpacer(7) - sizer.Add(wx.StaticText(self, -1, _(u"Threshold")), (11, 0), (1, 6), flag=wx.LEFT, border=9) - sizer.Add(self.threshold, (12, 0), (1, 6), flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=9) - sizer.AddStretchSpacer((13, 0)) + sizer.Add(wx.StaticText(self, -1, _(u"Method")), flag=wx.LEFT, border=9) + sizer.AddSpacer(5) + sizer.Add(self.method_threshold, flag=wx.LEFT, border=11) + sizer.AddSpacer(5) + sizer.Add(self.threshold, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=13) + sizer.AddSpacer(5) + sizer.Add(self.method_dynamic, flag=wx.LEFT, border=11) + sizer.AddSpacer(5) + sizer.Add(self.deviation_min, flag=wx.LEFT, border=13) + sizer.Add(self.deviation_max, flag=wx.LEFT, border=13) + + sizer.AddSpacer(7) self.SetSizer(sizer) sizer.Fit(self) @@ -2119,6 +2150,8 @@ class FFillSegmentationOptionsDialog(wx.Dialog): self.Bind(wx.EVT_RADIOBUTTON, self.OnSetRadio) self.Bind(grad.EVT_THRESHOLD_CHANGING, self.OnSlideChanged, self.threshold) + self.deviation_min.Bind(wx.EVT_SPINCTRL, self.OnSetDeviation) + self.deviation_max.Bind(wx.EVT_SPINCTRL, self.OnSetDeviation) self.Bind(wx.EVT_CLOSE, self.OnClose) def OnSetRadio(self, evt): @@ -2142,11 +2175,21 @@ class FFillSegmentationOptionsDialog(wx.Dialog): elif self.conect3D_26.GetValue(): self.config.con_3d = 26 + # Method + if self.method_threshold.GetValue(): + self.config.method = 'threshold' + else: + self.config.method = 'dynamic' + def OnSlideChanged(self, evt): - self.config.t0 = self.threshold.GetMinValue() - self.config.t1 = self.threshold.GetMaxValue() + self.config.t0 = int(self.threshold.GetMinValue()) + self.config.t1 = int(self.threshold.GetMaxValue()) print self.config.t0, self.config.t1 + def OnSetDeviation(self, evt): + self.config.dev_max = self.deviation_max.GetValue() + self.config.dev_min = self.deviation_min.GetValue() + def OnClose(self, evt): if self.config.dlg_visible: Publisher.sendMessage('Disable style', const.SLICE_STATE_MASK_FFILL) -- libgit2 0.21.2