MCPcopy
hub / github.com/black0017/MedicalZooPytorch / create_sub_volumes

Function create_sub_volumes

lib/medloaders/medical_loader_utils.py:63–129  ·  view source on GitHub ↗

:param ls: list of modality paths, where the last path is the segmentation map :param dataset_name: which dataset is used :param mode: train/val :param samples: train/val samples to generate :param full_vol_dim: full image size :param crop_size: train volume size :param

(*ls, dataset_name, mode, samples, full_vol_dim, crop_size, sub_vol_path, normalization='max_min',
                       th_percent=0.1)

Source from the content-addressed store, hash-verified

61
62
63def create_sub_volumes(*ls, dataset_name, mode, samples, full_vol_dim, crop_size, sub_vol_path, normalization='max_min',
64 th_percent=0.1):
65 """
66
67 :param ls: list of modality paths, where the last path is the segmentation map
68 :param dataset_name: which dataset is used
69 :param mode: train/val
70 :param samples: train/val samples to generate
71 :param full_vol_dim: full image size
72 :param crop_size: train volume size
73 :param sub_vol_path: path for the particular patient
74 :param th_percent: the % of the croped dim that corresponds to non-zero labels
75 :param crop_type:
76 :return:
77 """
78 total = len(ls[0])
79 assert total != 0, "Problem reading data. Check the data paths."
80 modalities = len(ls)
81 list = []
82 # print(modalities)
83 # print(ls[2])
84
85 print('Mode: ' + mode + ' Subvolume samples to generate: ', samples, ' Volumes: ', total)
86 for i in range(samples):
87 # print(i)
88 random_index = np.random.randint(total)
89 sample_paths = []
90 tensor_images = []
91 for j in range(modalities):
92 sample_paths.append(ls[j][random_index])
93 # print(sample_paths)
94 while True:
95 label_path = sample_paths[-1]
96 crop = find_random_crop_dim(full_vol_dim, crop_size)
97 full_segmentation_map = img_loader.load_medical_image(label_path, viz3d=True, type='label',
98 crop_size=crop_size,
99 crop=crop)
100
101 full_segmentation_map = fix_seg_map(full_segmentation_map, dataset_name)
102 # print(full_segmentation_map.shape)
103 if find_non_zero_labels_mask(full_segmentation_map, th_percent, crop_size, crop):
104 segmentation_map = img_loader.load_medical_image(label_path, type='label', crop_size=crop_size,
105 crop=crop)
106 segmentation_map = fix_seg_map(segmentation_map, dataset_name)
107 for j in range(modalities - 1):
108 img_tensor = img_loader.load_medical_image(sample_paths[j], type="T1", normalization=normalization,
109 crop_size=crop_size, crop=crop)
110
111 tensor_images.append(img_tensor)
112
113 break
114
115 filename = sub_vol_path + 'id_' + str(random_index) + '_s_' + str(i) + '_modality_'
116 list_saved_paths = []
117 for j in range(modalities - 1):
118 f_t1 = filename + str(j) + '.npy'
119 list_saved_paths.append(f_t1)
120

Callers 7

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90

Calls 3

find_random_crop_dimFunction · 0.85
fix_seg_mapFunction · 0.85

Tested by

no test coverage detected