-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_files.py
56 lines (39 loc) · 1.6 KB
/
check_files.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
"""
This script removes unecessary use of space-other in the spinegeneric datasets.
"""
import os
import glob
from vrac.data_management.image import Image
from vrac.data_management.utils import get_img_path_from_label_path
def main():
# Add variables
bids_folder = '/Users/nathan/data/data-multi-subject'
key_word = 'canal'
dim = []
ori = []
missing_files = []
labels_to_check = glob.glob(bids_folder + '/derivatives/labels' + '/**/' + f'*{key_word}*.nii.gz', recursive=True)
for label_path in labels_to_check:
img_path = get_img_path_from_label_path(label_path)
if not os.path.exists(img_path):
print(f'File {img_path} is missing !')
missing_files.append(img_path)
else:
# Load image
img = Image(img_path)
# Load label
label = Image(label_path)
if img.orientation != label.orientation:
ori.append(img_path)
print(f'{label.orientation} for {label_path} while {img.orientation} for {img_path}')
# Check if equal size
img.change_orientation('RPI')
label.change_orientation('RPI')
if img.dim[:3] != label.dim[:3]:
dim.append(label_path)
print(f'ERROR with {label_path}')
print("missing files:\n" + '\n'.join(sorted(missing_files)))
print("ori err files:\n" + '\n'.join(sorted(ori)))
print("dim err files:\n" + '\n'.join(sorted(dim)))
if __name__=='__main__':
main()