Commit 5a215327706c56ede518ec503311243a7bded8e2

Authored by Thiago Franco de Moraes
1 parent f6fab930

Starting 3d confidence

Showing 1 changed file with 33 additions and 28 deletions   Show diff stats
invesalius/data/styles.py
... ... @@ -2056,7 +2056,11 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle):
2056 2056 dy, dx = image.shape
2057 2057 image = image.reshape((1, dy, dx))
2058 2058 mask = mask.reshape((1, dy, dx))
2059   - out_mask = self.do_rg_confidence((x, y, 0), image, mask)
  2059 +
  2060 + bstruct = np.array(generate_binary_structure(2, CON2D[self.config.con_2d]), dtype='uint8')
  2061 + bstruct = bstruct.reshape((1, 3, 3))
  2062 +
  2063 + out_mask = self.do_rg_confidence(image, mask, (x, y, 0), bstruct)
2060 2064 else:
2061 2065 if self.config.method == 'threshold':
2062 2066 v = image[y, x]
... ... @@ -2114,47 +2118,51 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle):
2114 2118 mask = self.viewer.slice_.current_mask.matrix[1:, 1:, 1:]
2115 2119 image = self.viewer.slice_.matrix
2116 2120  
2117   - if self.config.method == 'threshold':
2118   - v = image[z, y, x]
2119   - t0 = self.config.t0
2120   - t1 = self.config.t1
  2121 + if self.config.method != 'confidence':
  2122 + if self.config.method == 'threshold':
  2123 + v = image[z, y, x]
  2124 + t0 = self.config.t0
  2125 + t1 = self.config.t1
2121 2126  
2122   - elif self.config.method == 'dynamic':
2123   - if self.config.use_ww_wl:
2124   - print "Using WW&WL"
2125   - ww = self.viewer.slice_.window_width
2126   - wl = self.viewer.slice_.window_level
2127   - image = get_LUT_value_255(image, ww, wl)
  2127 + elif self.config.method == 'dynamic':
  2128 + if self.config.use_ww_wl:
  2129 + print "Using WW&WL"
  2130 + ww = self.viewer.slice_.window_width
  2131 + wl = self.viewer.slice_.window_level
  2132 + image = get_LUT_value_255(image, ww, wl)
2128 2133  
2129   - v = image[z, y, x]
  2134 + v = image[z, y, x]
2130 2135  
2131   - t0 = v - self.config.dev_min
2132   - t1 = v + self.config.dev_max
  2136 + t0 = v - self.config.dev_min
  2137 + t1 = v + self.config.dev_max
2133 2138  
2134   - if image[z, y, x] < t0 or image[z, y, x] > t1:
2135   - return
  2139 + if image[z, y, x] < t0 or image[z, y, x] > t1:
  2140 + return
2136 2141  
2137   - out_mask = np.zeros_like(mask)
2138 2142  
2139 2143 bstruct = np.array(generate_binary_structure(3, CON3D[self.config.con_3d]), dtype='uint8')
2140 2144 self.viewer.slice_.do_threshold_to_all_slices()
2141 2145 cp_mask = self.viewer.slice_.current_mask.matrix.copy()
2142 2146  
2143   - with futures.ThreadPoolExecutor(max_workers=1) as executor:
2144   - future = executor.submit(floodfill.floodfill_threshold, image, [[x, y, z]], t0, t1, 1, bstruct, out_mask)
  2147 + if self.config.method == 'confidence':
  2148 + out_mask = self.do_rg_confidence(image, mask, (x, y, z), bstruct)
  2149 + else:
  2150 + out_mask = np.zeros_like(mask)
  2151 + with futures.ThreadPoolExecutor(max_workers=1) as executor:
  2152 + future = executor.submit(floodfill.floodfill_threshold, image, [[x, y, z]], t0, t1, 1, bstruct, out_mask)
2145 2153  
2146   - dlg = wx.ProgressDialog(self._progr_title, self._progr_msg, parent=None, style=wx.PD_APP_MODAL)
2147   - while not future.done():
2148   - dlg.Pulse()
2149   - time.sleep(0.1)
  2154 + dlg = wx.ProgressDialog(self._progr_title, self._progr_msg, parent=None, style=wx.PD_APP_MODAL)
  2155 + while not future.done():
  2156 + dlg.Pulse()
  2157 + time.sleep(0.1)
2150 2158  
2151   - dlg.Destroy()
  2159 + dlg.Destroy()
2152 2160  
2153 2161 mask[out_mask.astype('bool')] = self.config.fill_value
2154 2162  
2155 2163 self.viewer.slice_.current_mask.save_history(0, 'VOLUME', self.viewer.slice_.current_mask.matrix.copy(), cp_mask)
2156 2164  
2157   - def do_rg_confidence(self, p, image, mask):
  2165 + def do_rg_confidence(self, image, mask, p, bstruct):
2158 2166 x, y, z = p
2159 2167 if self.config.use_ww_wl:
2160 2168 print "Using WW&WL"
... ... @@ -2172,9 +2180,6 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle):
2172 2180 bool_mask[0, j, i] = True
2173 2181  
2174 2182  
2175   - bstruct = np.array(generate_binary_structure(2, CON2D[self.config.con_2d]), dtype='uint8')
2176   - bstruct = bstruct.reshape((1, 3, 3))
2177   -
2178 2183 for i in xrange(3):
2179 2184 var = np.std(image[bool_mask])
2180 2185 mean = np.mean(image[bool_mask])
... ...