-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_params.py
64 lines (52 loc) · 1.96 KB
/
calculate_params.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
from glob import glob
from monai.data import Dataset, DatasetSummary
from monai.transforms import LoadImaged
def get_task_params(args):
"""
This function is used to achieve the spacings of decathlon dataset.
In addition, for CT images (task 03, 06, 07, 08, 09 and 10), this function
also prints the mean and std values (used for normalization), and the min (0.5 percentile)
and max(99.5 percentile) values (used for clip).
"""
root_dir = args.root_dir
train_image_paths = glob(os.path.join(root_dir, "images", "*.nii.gz"))
train_image_paths.sort()
train_label_paths = glob(os.path.join(root_dir, "labels", "*.nii.gz"))
train_label_paths.sort()
data_dicts = tuple(
{"image": img, "label": label}
for img, label in zip(train_image_paths, train_label_paths)
)
# print(data_dicts)
dataset = Dataset(
data=data_dicts,
transform=LoadImaged(keys=["image", "label"], reader="nibabelreader"),
)
calculator = DatasetSummary(dataset, num_workers=4)
target_spacing = calculator.get_target_spacing()
print("spacing: ", target_spacing)
print("CT input, calculate statistics:")
calculator.calculate_statistics()
print("mean: ", calculator.data_mean, " std: ", calculator.data_std)
calculator.calculate_percentiles(
sampling_flag=True, interval=10, min_percentile=0.5, max_percentile=99.5
)
print(
"min: ",
calculator.data_min_percentile,
" max: ",
calculator.data_max_percentile,
)
if __name__ == "__main__":
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument(
"-root_dir",
"--root_dir",
type=str,
default="/mnt/HDD2/flare2022/datasets/FLARE2022/Training/FLARE22_LabeledCase50/",
help="dataset path",
)
args = parser.parse_args()
get_task_params(args)