-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_preprocessing_benedict.py
executable file
·54 lines (35 loc) · 1.5 KB
/
image_preprocessing_benedict.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
from ThreeDLabeler import preprocessing as pp
import os
import numpy as np
import nibabel as nib
BASE_DIR = ('/mnt/Storage2/Hallgrimsson/Automated_Phenotyping/Global/' +
'ALL_MICE/Source/')
TAG_DIR = ("/mnt/Storage2/Hallgrimsson/Automated_Phenotyping/Global/ALL_MICE" +
'/Source/txt')
MNC_DIR = ("/mnt/Storage2/Hallgrimsson/Automated_Phenotyping/Global/ALL_MICE" +
'/Source/MNC')
tag_files = os.listdir(TAG_DIR)
mnc_files = os.listdir(MNC_DIR)
mnc_files = [i for i in mnc_files if '.mnc' in i] # necessary for removing png
tag_files = [i for i in tag_files if '.tag' in i]
mnc_num = [i.split('_to_Global')[0] for i in mnc_files]
tag_num = [i.split('_landmar')[0] for i in tag_files]
mnc_num = np.array(mnc_num)
mnc_files = np.array(mnc_files)
tag_num = np.array(tag_num)
tag_files = np.array(tag_files)
diff_files = np.setdiff1d(tag_num, mnc_num)
assert diff_files.shape == (1,) # to make sure there aren't more than one.
tag_files = np.delete(tag_files, np.where(tag_num == diff_files[0]))
tag_num = np.delete(tag_num, np.where(tag_num == diff_files[0]))
assert np.alltrue(tag_num == mnc_num)
pp.package_to_npy(BASE_DIR, mnc_files[:3],
tag_files[:3],
mnc_num[:3],
mnc_sub_folder='MNC/',
tag_sub_folder='txt/',
output_path='/home/kail/NewSkulls')
img = nib.load(MNC_DIR+'/'+mnc_files[0])
tag1 = pp.tag_parser(TAG_DIR+'/'+tag_files[0])
test = pp.Image(img.get_data(), tag1)
test.cube().scale