Spaces:
Sleeping
Sleeping
Support for setting closing smoothing radius [no ci]
Browse files- lungtumormask/__main__.py +3 -1
- lungtumormask/dataprocessing.py +2 -2
- lungtumormask/mask.py +2 -2
lungtumormask/__main__.py
CHANGED
@@ -16,8 +16,10 @@ def main():
|
|
16 |
parser.add_argument('--lung-filter', action='store_true', help='whether to apply lungmask postprocessing.')
|
17 |
parser.add_argument('--threshold', metavar='threshold', type=float, default=0.5,
|
18 |
help='which threshold to use for assigning voxel-wise classes.')
|
|
|
|
|
19 |
|
20 |
argsin = sys.argv[1:]
|
21 |
args = parser.parse_args(argsin)
|
22 |
|
23 |
-
mask.mask(args.input, args.output, args.lung_filter, args.threshold)
|
|
|
16 |
parser.add_argument('--lung-filter', action='store_true', help='whether to apply lungmask postprocessing.')
|
17 |
parser.add_argument('--threshold', metavar='threshold', type=float, default=0.5,
|
18 |
help='which threshold to use for assigning voxel-wise classes.')
|
19 |
+
parser.add_argument('--radius', metavar='radius', type=int, default=5,
|
20 |
+
help='which radius to use for morphological post-processing segmentation smoothing.')
|
21 |
|
22 |
argsin = sys.argv[1:]
|
23 |
args = parser.parse_args(argsin)
|
24 |
|
25 |
+
mask.mask(args.input, args.output, args.lung_filter, args.threshold, args.radius)
|
lungtumormask/dataprocessing.py
CHANGED
@@ -219,7 +219,7 @@ def stitch(org_shape, cropped, roi):
|
|
219 |
|
220 |
return holder
|
221 |
|
222 |
-
def post_process(left, right, preprocess_dump, lung_filter, threshold):
|
223 |
left = remove_pad(left, preprocess_dump['left_lung'].squeeze(0).squeeze(0).numpy())
|
224 |
right = remove_pad(right, preprocess_dump['right_lung'].squeeze(0).squeeze(0).numpy())
|
225 |
|
@@ -239,6 +239,6 @@ def post_process(left, right, preprocess_dump, lung_filter, threshold):
|
|
239 |
stitched[preprocess_dump['lungmask'] == 0] = 0
|
240 |
|
241 |
# final post-processing - fix fragmentation
|
242 |
-
stitched = binary_closing(stitched, footprint=ball(radius=
|
243 |
|
244 |
return stitched
|
|
|
219 |
|
220 |
return holder
|
221 |
|
222 |
+
def post_process(left, right, preprocess_dump, lung_filter, threshold, radius):
|
223 |
left = remove_pad(left, preprocess_dump['left_lung'].squeeze(0).squeeze(0).numpy())
|
224 |
right = remove_pad(right, preprocess_dump['right_lung'].squeeze(0).squeeze(0).numpy())
|
225 |
|
|
|
239 |
stitched[preprocess_dump['lungmask'] == 0] = 0
|
240 |
|
241 |
# final post-processing - fix fragmentation
|
242 |
+
stitched = binary_closing(stitched, footprint=ball(radius=radius))
|
243 |
|
244 |
return stitched
|
lungtumormask/mask.py
CHANGED
@@ -15,7 +15,7 @@ def load_model():
|
|
15 |
model.eval()
|
16 |
return model
|
17 |
|
18 |
-
def mask(image_path, save_path, lung_filter, threshold):
|
19 |
print("Loading model...")
|
20 |
model = load_model()
|
21 |
|
@@ -27,7 +27,7 @@ def mask(image_path, save_path, lung_filter, threshold):
|
|
27 |
right = model(preprocess_dump['right_lung']).squeeze(0).squeeze(0).detach().numpy()
|
28 |
|
29 |
print("Post-processing image...")
|
30 |
-
inferred = post_process(left, right, preprocess_dump, lung_filter, threshold).astype("uint8")
|
31 |
|
32 |
print(f"Storing segmentation at {save_path}")
|
33 |
nimage = nibabel.Nifti1Image(inferred, preprocess_dump['org_affine'])
|
|
|
15 |
model.eval()
|
16 |
return model
|
17 |
|
18 |
+
def mask(image_path, save_path, lung_filter, threshold, radius):
|
19 |
print("Loading model...")
|
20 |
model = load_model()
|
21 |
|
|
|
27 |
right = model(preprocess_dump['right_lung']).squeeze(0).squeeze(0).detach().numpy()
|
28 |
|
29 |
print("Post-processing image...")
|
30 |
+
inferred = post_process(left, right, preprocess_dump, lung_filter, threshold, radius).astype("uint8")
|
31 |
|
32 |
print(f"Storing segmentation at {save_path}")
|
33 |
nimage = nibabel.Nifti1Image(inferred, preprocess_dump['org_affine'])
|