Commit f70373d89ff988945a02efbe1faf100de01522e0

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

Split 2D and 3D segmentation

Showing 1 changed file with 21 additions and 22 deletions   Show diff stats
invesalius/data/styles.py
@@ -1917,13 +1917,13 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): @@ -1917,13 +1917,13 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle):
1917 viewer = self.viewer 1917 viewer = self.viewer
1918 iren = viewer.interactor 1918 iren = viewer.interactor
1919 mouse_x, mouse_y = iren.GetEventPosition() 1919 mouse_x, mouse_y = iren.GetEventPosition()
1920 - x, y, z = self.viewer.get_voxel_coord_by_screen_pos(mouse_x, mouse_y, self.picker) 1920 + x, y = self.viewer.get_slice_pixel_coord_by_screen_pos(mouse_x, mouse_y, self.picker)
1921 1921
1922 - mask = self.viewer.slice_.current_mask.matrix[1:, 1:, 1:]  
1923 - image = self.viewer.slice_.matrix 1922 + mask = self.viewer.slice_.buffer_slices[self.orientation].mask.copy()
  1923 + image = self.viewer.slice_.buffer_slices[self.orientation].image
1924 1924
1925 if self.config.method == 'threshold': 1925 if self.config.method == 'threshold':
1926 - v = image[z, y, x] 1926 + v = image[y, x]
1927 t0 = self.config.t0 1927 t0 = self.config.t0
1928 t1 = self.config.t1 1928 t1 = self.config.t1
1929 1929
@@ -1934,37 +1934,36 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): @@ -1934,37 +1934,36 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle):
1934 wl = self.viewer.slice_.window_level 1934 wl = self.viewer.slice_.window_level
1935 image = get_LUT_value(image, ww, wl) 1935 image = get_LUT_value(image, ww, wl)
1936 1936
1937 - v = image[z, y, x] 1937 + v = image[y, x]
1938 1938
1939 t0 = v - self.config.dev_min 1939 t0 = v - self.config.dev_min
1940 t1 = v + self.config.dev_max 1940 t1 = v + self.config.dev_max
1941 1941
1942 - if image[z, y, x] < t0 or image[z, y, x] > t1: 1942 + print v, x, y
  1943 + if image[y, x] < t0 or image[y, x] > t1:
1943 return 1944 return
1944 1945
1945 - _bstruct = generate_binary_structure(2, CON2D[self.config.con_2d])  
1946 - if self.orientation == 'AXIAL':  
1947 - bstruct = np.zeros((1, 3, 3), dtype='uint8')  
1948 - bstruct[0] = _bstruct  
1949 - elif self.orientation == 'CORONAL':  
1950 - bstruct = np.zeros((3, 1, 3), dtype='uint8')  
1951 - bstruct[:, 0, :] = _bstruct  
1952 - elif self.orientation == 'SAGITAL':  
1953 - bstruct = np.zeros((3, 3, 1), dtype='uint8')  
1954 - bstruct[:, :, 0] = _bstruct 1946 + dy, dx = image.shape
  1947 + image = image.reshape((1, dy, dx))
  1948 + mask = mask.reshape((1, dy, dx))
  1949 +
  1950 + bstruct = np.array(generate_binary_structure(2, CON2D[self.config.con_2d]), dtype='uint8')
  1951 + bstruct = bstruct.reshape((1, 3, 3))
  1952 +
  1953 + floodfill.floodfill_threshold(image, [[x, y, 0]], t0, t1, self.config.fill_value, bstruct, mask)
1955 1954
1956 - floodfill.floodfill_threshold(image, [[x, y, z]], t0, t1, self.config.fill_value, bstruct, mask)  
1957 - b_mask = self.viewer.slice_.buffer_slices[self.orientation].mask  
1958 index = self.viewer.slice_.buffer_slices[self.orientation].index 1955 index = self.viewer.slice_.buffer_slices[self.orientation].index
  1956 + b_mask = self.viewer.slice_.buffer_slices[self.orientation].mask
  1957 + vol_mask = self.viewer.slice_.current_mask.matrix[1:, 1:, 1:]
1959 1958
1960 if self.orientation == 'AXIAL': 1959 if self.orientation == 'AXIAL':
1961 - p_mask = mask[index,:,:].copy() 1960 + vol_mask[index, :, :] = mask
1962 elif self.orientation == 'CORONAL': 1961 elif self.orientation == 'CORONAL':
1963 - p_mask = mask[:, index, :].copy() 1962 + vol_mask[:, index, :] = mask
1964 elif self.orientation == 'SAGITAL': 1963 elif self.orientation == 'SAGITAL':
1965 - p_mask = mask[:, :, index].copy() 1964 + vol_mask[:, :, index] = mask
1966 1965
1967 - self.viewer.slice_.current_mask.save_history(index, self.orientation, p_mask, b_mask) 1966 + self.viewer.slice_.current_mask.save_history(index, self.orientation, mask, b_mask)
1968 1967
1969 def do_3d_seg(self): 1968 def do_3d_seg(self):
1970 viewer = self.viewer 1969 viewer = self.viewer