Spaces:
Running
Running
added lung mask postprocessing of tumor volume
Browse files
lungtumormask/dataprocessing.py
CHANGED
@@ -145,6 +145,7 @@ def preprocess(image_path):
|
|
145 |
|
146 |
print("Segmenting lungs...")
|
147 |
masked_lungs = mask_lung(image_path, 5)
|
|
|
148 |
right_lung_extreme = calculate_extremes(masked_lungs[0], 1)
|
149 |
preprocess_dump['right_extremes'] = right_lung_extreme
|
150 |
right_lung_processed = process_lung_scan(scan_dict, right_lung_extreme)
|
@@ -231,12 +232,10 @@ def post_process(left_mask, right_mask, preprocess_dump):
|
|
231 |
|
232 |
left_mask[left_mask >= 0.5] = 1
|
233 |
left_mask[left_mask < 0.5] = 0
|
234 |
-
|
235 |
left_mask = left_mask.astype(int)
|
236 |
|
237 |
right_mask[right_mask >= 0.5] = 1
|
238 |
right_mask[right_mask < 0.5] = 0
|
239 |
-
|
240 |
right_mask = right_mask.astype(int)
|
241 |
|
242 |
left = remove_pad(left_mask, preprocess_dump['left_lung'].squeeze(0).squeeze(0).numpy())
|
@@ -250,4 +249,7 @@ def post_process(left_mask, right_mask, preprocess_dump):
|
|
250 |
|
251 |
stitched = np.logical_or(left, right).astype(int)
|
252 |
|
|
|
|
|
|
|
253 |
return stitched
|
|
|
145 |
|
146 |
print("Segmenting lungs...")
|
147 |
masked_lungs = mask_lung(image_path, 5)
|
148 |
+
preprocess_dump['lungmask'] = masked_lungs
|
149 |
right_lung_extreme = calculate_extremes(masked_lungs[0], 1)
|
150 |
preprocess_dump['right_extremes'] = right_lung_extreme
|
151 |
right_lung_processed = process_lung_scan(scan_dict, right_lung_extreme)
|
|
|
232 |
|
233 |
left_mask[left_mask >= 0.5] = 1
|
234 |
left_mask[left_mask < 0.5] = 0
|
|
|
235 |
left_mask = left_mask.astype(int)
|
236 |
|
237 |
right_mask[right_mask >= 0.5] = 1
|
238 |
right_mask[right_mask < 0.5] = 0
|
|
|
239 |
right_mask = right_mask.astype(int)
|
240 |
|
241 |
left = remove_pad(left_mask, preprocess_dump['left_lung'].squeeze(0).squeeze(0).numpy())
|
|
|
249 |
|
250 |
stitched = np.logical_or(left, right).astype(int)
|
251 |
|
252 |
+
# filter tumor predictions outside the predicted lung area
|
253 |
+
stitched[preprocess_dump['lungmask'] == 0] = 0
|
254 |
+
|
255 |
return stitched
|