Commit 2ae4385954ff8aebf1043d74030993ff3f9339c1
1 parent
f70373d8
Exists in
ffill_segmentation
Floodfill in clean mask then add it to current mask
Showing
1 changed file
with
19 additions
and
12 deletions
Show diff stats
invesalius/data/styles.py
@@ -1898,7 +1898,16 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): | @@ -1898,7 +1898,16 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): | ||
1898 | return | 1898 | return |
1899 | 1899 | ||
1900 | if self.config.target == "3D": | 1900 | if self.config.target == "3D": |
1901 | - self.do_3d_seg() | 1901 | + with futures.ThreadPoolExecutor(max_workers=1) as executor: |
1902 | + future = executor.submit(self.do_3d_seg) | ||
1903 | + | ||
1904 | + dlg = wx.ProgressDialog(self._progr_title, self._progr_msg, parent=None, style=wx.PD_APP_MODAL) | ||
1905 | + while not future.done(): | ||
1906 | + dlg.Pulse() | ||
1907 | + time.sleep(0.1) | ||
1908 | + | ||
1909 | + dlg.Destroy() | ||
1910 | + | ||
1902 | else: | 1911 | else: |
1903 | self.do_2d_seg() | 1912 | self.do_2d_seg() |
1904 | 1913 | ||
@@ -1939,7 +1948,6 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): | @@ -1939,7 +1948,6 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): | ||
1939 | t0 = v - self.config.dev_min | 1948 | t0 = v - self.config.dev_min |
1940 | t1 = v + self.config.dev_max | 1949 | t1 = v + self.config.dev_max |
1941 | 1950 | ||
1942 | - print v, x, y | ||
1943 | if image[y, x] < t0 or image[y, x] > t1: | 1951 | if image[y, x] < t0 or image[y, x] > t1: |
1944 | return | 1952 | return |
1945 | 1953 | ||
@@ -1947,10 +1955,14 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): | @@ -1947,10 +1955,14 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): | ||
1947 | image = image.reshape((1, dy, dx)) | 1955 | image = image.reshape((1, dy, dx)) |
1948 | mask = mask.reshape((1, dy, dx)) | 1956 | mask = mask.reshape((1, dy, dx)) |
1949 | 1957 | ||
1958 | + out_mask = np.zeros_like(mask) | ||
1959 | + | ||
1950 | bstruct = np.array(generate_binary_structure(2, CON2D[self.config.con_2d]), dtype='uint8') | 1960 | bstruct = np.array(generate_binary_structure(2, CON2D[self.config.con_2d]), dtype='uint8') |
1951 | bstruct = bstruct.reshape((1, 3, 3)) | 1961 | bstruct = bstruct.reshape((1, 3, 3)) |
1952 | 1962 | ||
1953 | - floodfill.floodfill_threshold(image, [[x, y, 0]], t0, t1, self.config.fill_value, bstruct, mask) | 1963 | + floodfill.floodfill_threshold(image, [[x, y, 0]], t0, t1, 1, bstruct, out_mask) |
1964 | + | ||
1965 | + mask[out_mask.astype('bool')] = self.config.fill_value | ||
1954 | 1966 | ||
1955 | index = self.viewer.slice_.buffer_slices[self.orientation].index | 1967 | index = self.viewer.slice_.buffer_slices[self.orientation].index |
1956 | b_mask = self.viewer.slice_.buffer_slices[self.orientation].mask | 1968 | b_mask = self.viewer.slice_.buffer_slices[self.orientation].mask |
@@ -1994,19 +2006,14 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): | @@ -1994,19 +2006,14 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): | ||
1994 | if image[z, y, x] < t0 or image[z, y, x] > t1: | 2006 | if image[z, y, x] < t0 or image[z, y, x] > t1: |
1995 | return | 2007 | return |
1996 | 2008 | ||
2009 | + out_mask = np.zeros_like(mask) | ||
2010 | + | ||
1997 | bstruct = np.array(generate_binary_structure(3, CON3D[self.config.con_3d]), dtype='uint8') | 2011 | bstruct = np.array(generate_binary_structure(3, CON3D[self.config.con_3d]), dtype='uint8') |
1998 | self.viewer.slice_.do_threshold_to_all_slices() | 2012 | self.viewer.slice_.do_threshold_to_all_slices() |
1999 | cp_mask = self.viewer.slice_.current_mask.matrix.copy() | 2013 | cp_mask = self.viewer.slice_.current_mask.matrix.copy() |
2000 | 2014 | ||
2001 | - with futures.ThreadPoolExecutor(max_workers=1) as executor: | ||
2002 | - future = executor.submit(floodfill.floodfill_threshold, image, [[x, y, z]], t0, t1, self.config.fill_value, bstruct, mask) | ||
2003 | - | ||
2004 | - dlg = wx.ProgressDialog(self._progr_title, self._progr_msg, parent=None, style=wx.PD_APP_MODAL) | ||
2005 | - while not future.done(): | ||
2006 | - dlg.Pulse() | ||
2007 | - time.sleep(0.1) | ||
2008 | - | ||
2009 | - dlg.Destroy() | 2015 | + floodfill.floodfill_threshold(image, [[x, y, z]], t0, t1, 1, bstruct, out_mask) |
2016 | + mask[out_mask.astype('bool')] = self.config.fill_value | ||
2010 | 2017 | ||
2011 | self.viewer.slice_.current_mask.save_history(0, 'VOLUME', self.viewer.slice_.current_mask.matrix.copy(), cp_mask) | 2018 | self.viewer.slice_.current_mask.save_history(0, 'VOLUME', self.viewer.slice_.current_mask.matrix.copy(), cp_mask) |
2012 | 2019 |