FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
preprocessing/example/example_native_space_preprocessor.py at main · BrainLesion/preprocessing · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
BrainLesion
/
preprocessing
Public
Notifications
You must be signed in to change notification settings
Fork
10
Star
39
Code
Issues
12
Pull requests
4
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
preprocessing
/
example
/
example_native_space_preprocessor.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
96 lines (84 loc) · 3.84 KB
Breadcrumbs
preprocessing
/
example
/
example_native_space_preprocessor.py
Copy path
File metadata and controls
96 lines (84 loc) · 3.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from
pathlib
import
Path
from
brainles_preprocessing
.
constants
import
Atlas
from
brainles_preprocessing
.
modality
import
CenterModality
,
Modality
from
brainles_preprocessing
.
normalization
.
percentile_normalizer
import
(
PercentileNormalizer
,
)
from
brainles_preprocessing
.
preprocessor
import
NativeSpacePreprocessor
from
brainles_preprocessing
.
defacing
import
QuickshearDefacer
def
preprocess
(
input_dir
:
Path
,
output_dir
:
Path
):
t1_file
=
list
(
input_dir
.
glob
(
"*t1.nii.gz"
))[
0
]
t1c_file
=
list
(
input_dir
.
glob
(
"*t1c.nii.gz"
))[
0
]
t2_file
=
list
(
input_dir
.
glob
(
"*t2.nii.gz"
))[
0
]
flair_file
=
list
(
input_dir
.
glob
(
"*fla.nii.gz"
))[
0
]
# Create output directories
raw_bet_dir
=
output_dir
/
"raw_bet"
raw_bet_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
norm_bet_dir
=
output_dir
/
"normalized_bet"
norm_bet_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
raw_skull_dir
=
output_dir
/
"raw_skull"
raw_skull_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
norm_skull_dir
=
output_dir
/
"normalized_skull"
norm_skull_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
raw_deface_dir
=
output_dir
/
"raw_defaced"
raw_deface_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
percentile_normalizer
=
PercentileNormalizer
()
center
=
CenterModality
(
modality_name
=
"t1c"
,
input_path
=
t1c_file
,
raw_bet_output_path
=
raw_bet_dir
/
f"t1c_bet_raw.nii.gz"
,
raw_skull_output_path
=
raw_skull_dir
/
f"t1c_skull_raw.nii.gz"
,
normalized_skull_output_path
=
norm_skull_dir
/
f"t1c_skull_normalized.nii.gz"
,
raw_defaced_output_path
=
raw_deface_dir
/
f"t1c_defaced_raw.nii.gz"
,
normalizer
=
percentile_normalizer
,
bet_mask_output_path
=
output_dir
/
f"bet_mask.nii.gz"
,
defacing_mask_output_path
=
output_dir
/
f"defacing_mask.nii.gz"
,
)
moving_modalities
=
[
Modality
(
modality_name
=
"t1"
,
input_path
=
t1_file
,
raw_bet_output_path
=
raw_bet_dir
/
f"t1_bet_raw.nii.gz"
,
raw_skull_output_path
=
raw_skull_dir
/
f"t1_skull_raw.nii.gz"
,
normalized_skull_output_path
=
norm_skull_dir
/
f"t1_skull_normalized.nii.gz"
,
raw_defaced_output_path
=
raw_deface_dir
/
f"t1_defaced_raw.nii.gz"
,
normalizer
=
percentile_normalizer
,
),
Modality
(
modality_name
=
"t2"
,
input_path
=
t2_file
,
raw_bet_output_path
=
raw_bet_dir
/
f"t2_bet_raw.nii.gz"
,
raw_skull_output_path
=
raw_skull_dir
/
f"t2_skull_raw.nii.gz"
,
normalized_skull_output_path
=
norm_skull_dir
/
f"t2_skull_normalized.nii.gz"
,
normalizer
=
percentile_normalizer
,
),
Modality
(
modality_name
=
"flair"
,
input_path
=
flair_file
,
raw_bet_output_path
=
raw_bet_dir
/
f"fla_bet_raw.nii.gz"
,
raw_skull_output_path
=
raw_skull_dir
/
f"fla_skull_raw.nii.gz"
,
normalized_skull_output_path
=
norm_skull_dir
/
f"fla_skull_normalized.nii.gz"
,
raw_defaced_output_path
=
raw_deface_dir
/
f"fla_defaced_raw.nii.gz"
,
normalizer
=
percentile_normalizer
,
),
]
preprocessor
=
NativeSpacePreprocessor
(
center_modality
=
center
,
moving_modalities
=
moving_modalities
,
limit_cuda_visible_devices
=
"0"
,
defacer
=
QuickshearDefacer
(
atlas_image_path
=
Atlas
.
MNI152
),
)
preprocessor
.
run
(
save_dir_coregistration
=
output_dir
/
"coregistration"
,
save_dir_n4_bias_correction
=
output_dir
/
"n4_bias_correction"
,
save_dir_brain_extraction
=
output_dir
/
"brain_extraction"
,
save_dir_defacing
=
output_dir
/
"defacing"
,
)
if
__name__
==
"__main__"
:
subject
=
"TCGA-DU-7294"
# "OtherEXampleFromTCIA"
base_dir
=
Path
(
__file__
).
parent
preprocess
(
input_dir
=
Path
(
base_dir
/
f"example_data/
{
subject
}
"
),
output_dir
=
Path
(
base_dir
/
f"example_data/native_space_preprocessed_
{
subject
}
"
),
)
Back
|
FazBrowse Home
|
New Git URL