-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathluna_s_local.py
70 lines (60 loc) · 3.55 KB
/
luna_s_local.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
65
66
67
68
69
70
import data_transforms
import data_iterators
import pathfinder
import configs_seg_patch.luna_p_local as patch_config
import lung_segmentation
# rng = patch_config.rng
# p_transform_patch = patch_config.p_transform
#
# p_transform = {'patch_size': (416, 416, 416),
# 'mm_patch_size': (416, 416, 416),
# 'pixel_spacing': patch_config.p_transform['pixel_spacing']
# }
#
#
# def data_prep_function(data, pixel_spacing, p_transform=p_transform):
# # MAKE SURE THAT DATA IS PREPROCESSED THE SAME WAY
# x, tf_matrix = data_transforms.transform_scan3d(data=data,
# pixel_spacing=pixel_spacing,
# p_transform=p_transform,
# p_transform_augment=None)
# x = data_transforms.pixelnormHU(x)
# return x, tf_matrix
#
#
# data_iterator = data_iterators.DSBScanDataGenerator(data_path=pathfinder.DATA_PATH,
# transform_params=p_transform,
# data_prep_fun=data_prep_function)
rng = patch_config.rng
# calculate the following things correctly!
p_transform = {'patch_size': (416, 416, 416),
'mm_patch_size': (416, 416, 416),
'pixel_spacing': patch_config.p_transform['pixel_spacing']
}
window_size = 160
stride = 128
n_windows = (p_transform['patch_size'][0] - window_size) / stride + 1
valid_pids = patch_config.valid_pids
def data_prep_function(data, luna_annotations, pixel_spacing, luna_origin,
p_transform=p_transform,
p_transform_augment=None):
# make sure the data is processed the same way
lung_mask = lung_segmentation.segment_HU_scan_frederic(data)
x, annotations_tf, tf_matrix, lung_mask_out = data_transforms.transform_scan3d(data=data,
pixel_spacing=pixel_spacing,
p_transform=p_transform,
luna_annotations=luna_annotations,
p_transform_augment=None,
luna_origin=luna_origin,
lung_mask=lung_mask)
# x = data_transforms.pixelnormHU(x)
y = data_transforms.make_3d_mask_from_annotations(img_shape=x.shape, annotations=annotations_tf, shape='sphere')
return x, y, lung_mask_out, annotations_tf, tf_matrix
valid_data_iterator = data_iterators.LunaScanPositiveLungMaskDataGenerator(data_path=pathfinder.LUNA_DATA_PATH,
transform_params=p_transform,
data_prep_fun=data_prep_function,
rng=rng,
batch_size=1,
patient_ids=valid_pids,
full_batch=True,
random=False, infinite=False)