Commit c0352ef3b6d871b194e76934fc3d71d9ed289021
1 parent
6e437a17
Exists in
region_growing_confidence
2D confidence
Showing
1 changed file
with
53 additions
and
1 deletions
Show diff stats
invesalius/data/styles.py
... | ... | @@ -2057,7 +2057,7 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): |
2057 | 2057 | t0 = self.config.t0 |
2058 | 2058 | t1 = self.config.t1 |
2059 | 2059 | |
2060 | - elif self.config.method == 'dynamic': | |
2060 | + elif self.config.method == 'dynamic1': | |
2061 | 2061 | if self.config.use_ww_wl: |
2062 | 2062 | print "Using WW&WL" |
2063 | 2063 | ww = self.viewer.slice_.window_width |
... | ... | @@ -2069,6 +2069,58 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): |
2069 | 2069 | t0 = v - self.config.dev_min |
2070 | 2070 | t1 = v + self.config.dev_max |
2071 | 2071 | |
2072 | + else: | |
2073 | + dy, dx = image.shape | |
2074 | + image = image.reshape((1, dy, dx)) | |
2075 | + mask = mask.reshape((1, dy, dx)) | |
2076 | + if self.config.use_ww_wl: | |
2077 | + print "Using WW&WL" | |
2078 | + ww = self.viewer.slice_.window_width | |
2079 | + wl = self.viewer.slice_.window_level | |
2080 | + image = get_LUT_value_255(image, ww, wl) | |
2081 | + bool_mask = np.zeros_like(mask, dtype='bool') | |
2082 | + out_mask = np.zeros_like(mask) | |
2083 | + for i in xrange(int(x-1), int(x+2)): | |
2084 | + if i < 0 or i >= bool_mask.shape[2]: | |
2085 | + continue | |
2086 | + for j in xrange(int(y-1), int(y+2)): | |
2087 | + if j < 0 or j >= bool_mask.shape[1]: | |
2088 | + continue | |
2089 | + bool_mask[0, j, i] = True | |
2090 | + | |
2091 | + | |
2092 | + bstruct = np.array(generate_binary_structure(2, CON2D[self.config.con_2d]), dtype='uint8') | |
2093 | + bstruct = bstruct.reshape((1, 3, 3)) | |
2094 | + | |
2095 | + for i in xrange(3): | |
2096 | + var = np.std(image[bool_mask]) | |
2097 | + mean = np.mean(image[bool_mask]) | |
2098 | + | |
2099 | + t0 = mean - var * 2.5 | |
2100 | + t1 = mean + var * 2.5 | |
2101 | + print var, mean, t0, t1 | |
2102 | + | |
2103 | + floodfill.floodfill_threshold(image, [[x, y, 0]], t0, t1, 1, bstruct, out_mask) | |
2104 | + | |
2105 | + bool_mask[out_mask == 1] = True | |
2106 | + | |
2107 | + mask[out_mask.astype('bool')] = self.config.fill_value | |
2108 | + | |
2109 | + index = self.viewer.slice_.buffer_slices[self.orientation].index | |
2110 | + b_mask = self.viewer.slice_.buffer_slices[self.orientation].mask | |
2111 | + vol_mask = self.viewer.slice_.current_mask.matrix[1:, 1:, 1:] | |
2112 | + | |
2113 | + if self.orientation == 'AXIAL': | |
2114 | + vol_mask[index, :, :] = mask | |
2115 | + elif self.orientation == 'CORONAL': | |
2116 | + vol_mask[:, index, :] = mask | |
2117 | + elif self.orientation == 'SAGITAL': | |
2118 | + vol_mask[:, :, index] = mask | |
2119 | + | |
2120 | + self.viewer.slice_.current_mask.save_history(index, self.orientation, mask, b_mask) | |
2121 | + | |
2122 | + return | |
2123 | + | |
2072 | 2124 | if image[y, x] < t0 or image[y, x] > t1: |
2073 | 2125 | return |
2074 | 2126 | ... | ... |