Commit bb286f6d662fea7a86ff4d898d0f9506da9b01ae

Authored by Thiago Franco de Moraes
1 parent b26abc58
Exists in ffill_segmentation

Segmetation dynamic

invesalius/data/styles.py
... ... @@ -1854,6 +1854,11 @@ class FFillSegmentationConfig(object):
1854 1854  
1855 1855 self.fill_value = 254
1856 1856  
  1857 + self.method = 'threshold'
  1858 +
  1859 + self.dev_min = 50
  1860 + self.dev_max = 50
  1861 +
1857 1862  
1858 1863 class FloodFillSegmentInteractorStyle(DefaultInteractorStyle):
1859 1864 def __init__(self, viewer):
... ... @@ -1898,9 +1903,20 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle):
1898 1903 mask = self.viewer.slice_.current_mask.matrix[1:, 1:, 1:]
1899 1904 image = self.viewer.slice_.matrix
1900 1905  
1901   - print image[z, y, x]
  1906 + v = image[z, y, x]
  1907 + print v
  1908 +
  1909 + if self.config.method == 'threshold':
  1910 + t0 = self.config.t0
  1911 + t1 = self.config.t1
  1912 + elif self.config.method == 'dynamic':
  1913 + print 'Method dynamic'
  1914 + t0 = v - self.config.dev_min
  1915 + t1 = v + self.config.dev_max
  1916 +
  1917 + print v, t0, t1
1902 1918  
1903   - if image[z, y, x] < self.config.t0 or image[z, y, x] > self.config.t1:
  1919 + if image[z, y, x] < t0 or image[z, y, x] > t1:
1904 1920 return
1905 1921  
1906 1922 if self.config.target == "3D":
... ... @@ -1920,7 +1936,7 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle):
1920 1936 bstruct[:, :, 0] = _bstruct
1921 1937  
1922 1938 if self.config.target == '2D':
1923   - floodfill.floodfill_threshold(image, [[x, y, z]], self.config.t0, self.config.t1, self.config.fill_value, bstruct, mask)
  1939 + floodfill.floodfill_threshold(image, [[x, y, z]], t0, t1, self.config.fill_value, bstruct, mask)
1924 1940 b_mask = self.viewer.slice_.buffer_slices[self.orientation].mask
1925 1941 index = self.viewer.slice_.buffer_slices[self.orientation].index
1926 1942  
... ... @@ -1934,7 +1950,7 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle):
1934 1950 self.viewer.slice_.current_mask.save_history(index, self.orientation, p_mask, b_mask)
1935 1951 else:
1936 1952 with futures.ThreadPoolExecutor(max_workers=1) as executor:
1937   - future = executor.submit(floodfill.floodfill_threshold, image, [[x, y, z]], self.config.t0, self.config.t1, self.config.fill_value, bstruct, mask)
  1953 + future = executor.submit(floodfill.floodfill_threshold, image, [[x, y, z]], t0, t1, self.config.fill_value, bstruct, mask)
1938 1954  
1939 1955 dlg = wx.ProgressDialog(self._progr_title, self._progr_msg, parent=None, style=wx.PD_APP_MODAL)
1940 1956 while not future.done():
... ...
invesalius/gui/dialogs.py
... ... @@ -2086,32 +2086,63 @@ class FFillSegmentationOptionsDialog(wx.Dialog):
2086 2086 self.threshold = grad.GradientCtrl(self, -1, int(bound_min),
2087 2087 int(bound_max), self.config.t0,
2088 2088 self.config.t1, colour)
  2089 + self.threshold.SetMinSize((250, -1))
  2090 +
  2091 + self.method_threshold = wx.RadioButton(self, -1, _(u"Threshold"), style=wx.RB_GROUP)
  2092 + self.method_dynamic = wx.RadioButton(self, -1, _(u"Dynamic"))
  2093 +
  2094 + if self.config.method == 'dynamic':
  2095 + self.method_dynamic.SetValue(1)
  2096 + else:
  2097 + self.method_threshold.SetValue(1)
  2098 + self.config.method = 'threshold'
  2099 +
  2100 + self.deviation_min = wx.SpinCtrl(self, -1, value='%d' % self.config.dev_min, min=0, max=10000)
  2101 + self.deviation_max = wx.SpinCtrl(self, -1, value='%d' % self.config.dev_max, min=0, max=10000)
2089 2102  
2090 2103 # Sizer
2091   - sizer = wx.GridBagSizer(15, 6)
2092   - sizer.AddStretchSpacer((0, 0))
  2104 + sizer = wx.BoxSizer(wx.VERTICAL)
2093 2105  
2094   - sizer.Add(wx.StaticText(self, -1, _(u"Parameters")), (1, 0), (1, 6), flag=wx.LEFT, border=7)
2095   - sizer.Add(self.target_2d, (2, 0), (1, 6), flag=wx.LEFT, border=9)
2096   - sizer.Add(self.target_3d, (3, 0), (1, 6), flag=wx.LEFT, border=9)
  2106 + sizer.AddSpacer(7)
2097 2107  
2098   - sizer.AddStretchSpacer((4, 0))
  2108 + sizer.Add(wx.StaticText(self, -1, _(u"Parameters")), flag=wx.LEFT, border=7)
  2109 + sizer.AddSpacer(5)
  2110 + sizer.Add(self.target_2d, flag=wx.LEFT, border=9)
  2111 + sizer.Add(self.target_3d, flag=wx.LEFT, border=9)
2099 2112  
2100   - sizer.Add(wx.StaticText(self, -1, _(u"2D Connectivity")), (5, 0), (1, 6), flag=wx.LEFT, border=9)
2101   - sizer.Add(self.conect2D_4, (6, 0), flag=wx.LEFT, border=9)
2102   - sizer.Add(self.conect2D_8, (6, 1), flag=wx.LEFT, border=9)
  2113 + sizer.AddSpacer(7)
2103 2114  
2104   - sizer.AddStretchSpacer((7, 0))
  2115 + sizer.Add(wx.StaticText(self, -1, _(u"2D Connectivity")), flag=wx.LEFT, border=9)
  2116 + sizer.AddSpacer(5)
  2117 + sizer_2d = wx.BoxSizer(wx.HORIZONTAL)
  2118 + sizer_2d.Add(self.conect2D_4, flag=wx.LEFT, border=11)
  2119 + sizer_2d.Add(self.conect2D_8, flag=wx.LEFT, border=11)
  2120 + sizer.Add(sizer_2d)
2105 2121  
2106   - sizer.Add(wx.StaticText(self, -1, _(u"3D Connectivity")), (8, 0), (1, 6), flag=wx.LEFT, border=9)
2107   - sizer.Add(self.conect3D_6, (9, 0), flag=wx.LEFT, border=9)
2108   - sizer.Add(self.conect3D_18, (9, 1), flag=wx.LEFT, border=9)
2109   - sizer.Add(self.conect3D_26, (9, 2), flag=wx.LEFT, border=9)
2110   - sizer.AddStretchSpacer((10, 0))
  2122 + sizer.AddSpacer(7)
  2123 +
  2124 + sizer.Add(wx.StaticText(self, -1, _(u"3D Connectivity")), flag=wx.LEFT, border=9)
  2125 + sizer.AddSpacer(5)
  2126 + sizer_3d = wx.BoxSizer(wx.HORIZONTAL)
  2127 + sizer_3d.Add(self.conect3D_6, flag=wx.LEFT, border=11)
  2128 + sizer_3d.Add(self.conect3D_18, flag=wx.LEFT, border=11)
  2129 + sizer_3d.Add(self.conect3D_26, flag=wx.LEFT, border=11)
  2130 + sizer.Add(sizer_3d)
  2131 +
  2132 + sizer.AddSpacer(7)
2111 2133  
2112   - sizer.Add(wx.StaticText(self, -1, _(u"Threshold")), (11, 0), (1, 6), flag=wx.LEFT, border=9)
2113   - sizer.Add(self.threshold, (12, 0), (1, 6), flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=9)
2114   - sizer.AddStretchSpacer((13, 0))
  2134 + sizer.Add(wx.StaticText(self, -1, _(u"Method")), flag=wx.LEFT, border=9)
  2135 + sizer.AddSpacer(5)
  2136 + sizer.Add(self.method_threshold, flag=wx.LEFT, border=11)
  2137 + sizer.AddSpacer(5)
  2138 + sizer.Add(self.threshold, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=13)
  2139 + sizer.AddSpacer(5)
  2140 + sizer.Add(self.method_dynamic, flag=wx.LEFT, border=11)
  2141 + sizer.AddSpacer(5)
  2142 + sizer.Add(self.deviation_min, flag=wx.LEFT, border=13)
  2143 + sizer.Add(self.deviation_max, flag=wx.LEFT, border=13)
  2144 +
  2145 + sizer.AddSpacer(7)
2115 2146  
2116 2147 self.SetSizer(sizer)
2117 2148 sizer.Fit(self)
... ... @@ -2119,6 +2150,8 @@ class FFillSegmentationOptionsDialog(wx.Dialog):
2119 2150  
2120 2151 self.Bind(wx.EVT_RADIOBUTTON, self.OnSetRadio)
2121 2152 self.Bind(grad.EVT_THRESHOLD_CHANGING, self.OnSlideChanged, self.threshold)
  2153 + self.deviation_min.Bind(wx.EVT_SPINCTRL, self.OnSetDeviation)
  2154 + self.deviation_max.Bind(wx.EVT_SPINCTRL, self.OnSetDeviation)
2122 2155 self.Bind(wx.EVT_CLOSE, self.OnClose)
2123 2156  
2124 2157 def OnSetRadio(self, evt):
... ... @@ -2142,11 +2175,21 @@ class FFillSegmentationOptionsDialog(wx.Dialog):
2142 2175 elif self.conect3D_26.GetValue():
2143 2176 self.config.con_3d = 26
2144 2177  
  2178 + # Method
  2179 + if self.method_threshold.GetValue():
  2180 + self.config.method = 'threshold'
  2181 + else:
  2182 + self.config.method = 'dynamic'
  2183 +
2145 2184 def OnSlideChanged(self, evt):
2146   - self.config.t0 = self.threshold.GetMinValue()
2147   - self.config.t1 = self.threshold.GetMaxValue()
  2185 + self.config.t0 = int(self.threshold.GetMinValue())
  2186 + self.config.t1 = int(self.threshold.GetMaxValue())
2148 2187 print self.config.t0, self.config.t1
2149 2188  
  2189 + def OnSetDeviation(self, evt):
  2190 + self.config.dev_max = self.deviation_max.GetValue()
  2191 + self.config.dev_min = self.deviation_min.GetValue()
  2192 +
2150 2193 def OnClose(self, evt):
2151 2194 if self.config.dlg_visible:
2152 2195 Publisher.sendMessage('Disable style', const.SLICE_STATE_MASK_FFILL)
... ...