Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spinal_dmri_pipeline
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Saad Jbabdi
spinal_dmri_pipeline
Merge requests
!3
Added report
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Added report
tumour_seg
into
main
Overview
0
Commits
1
Pipelines
0
Changes
3
Merged
Saad Jbabdi
requested to merge
tumour_seg
into
main
2 years ago
Overview
0
Commits
1
Pipelines
0
Changes
3
Expand
0
0
Merge request reports
Viewing commit
8750bea3
Show latest version
3 files
+
321
−
2
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
8750bea3
Added report
· 8750bea3
saad
authored
2 years ago
spinal_dmri_pipeline/scripts/fwdti.py
0 → 100755
+
78
−
0
Options
#!/usr/bin/env python
# Simple script for fitting Free-water eliminated DTI using DIPY
# Author: S. Jbabdi - 02/2022
import
argparse
p
=
argparse
.
ArgumentParser
(
"
Fit FOD
"
)
p
.
add_argument
(
'
--data
'
,
required
=
True
,
type
=
str
,
metavar
=
'
<IMAGE>
'
,
help
=
'
input DWI data
'
)
p
.
add_argument
(
'
--bvecs
'
,
required
=
True
,
type
=
str
,
metavar
=
'
<FILE>
'
,
help
=
'
bvecs ASCII text file
'
)
p
.
add_argument
(
'
--bvals
'
,
required
=
True
,
type
=
str
,
metavar
=
'
<FILE>
'
,
help
=
'
bvals ASCII text file
'
)
p
.
add_argument
(
'
--out
'
,
required
=
True
,
type
=
str
,
metavar
=
'
<str>
'
,
help
=
'
output basename
'
)
p
.
add_argument
(
'
--mask
'
,
required
=
True
,
type
=
str
,
metavar
=
'
<IMAGE>
'
,
help
=
'
brain mask
'
)
p
.
add_argument
(
'
--verbose
'
,
action
=
"
store_true
"
,
help
=
'
print info
'
)
# Parse Arguments here
args
=
p
.
parse_args
()
# ------------ Other imports
import
numpy
as
np
from
fsl.data.image
import
Image
# ----- dipy imports ------ #
import
dipy.reconst.fwdti
as
fwdti
from
dipy.core.gradients
import
gradient_table
# --- Start here
# Get data
if
args
.
verbose
:
print
(
'
Read data
'
)
data
=
Image
(
args
.
data
)
header
=
data
.
header
# store header info
data
=
data
.
data
# get data array
# Brain mask
mask
=
Image
(
args
.
mask
).
data
# bvals, bvecs text to array
bvals
=
np
.
loadtxt
(
args
.
bvals
)
bvecs
=
np
.
loadtxt
(
args
.
bvecs
).
T
bvecs
[
bvals
<
5
]
=
[
1
,
0
,
0
]
# fix in case bvecs=0,0,0
bvecs
=
bvecs
/
np
.
sqrt
(
np
.
sum
(
bvecs
**
2
,
axis
=
1
,
keepdims
=
True
))
# normalise
# Set gradient table
gtab
=
gradient_table
(
bvals
,
bvecs
)
# Fit ODF model
if
args
.
verbose
:
print
(
'
Fit model
'
)
fwdtimodel
=
fwdti
.
FreeWaterTensorModel
(
gtab
)
fwdtifit
=
fwdtimodel
.
fit
(
data
,
mask
=
mask
)
if
args
.
verbose
:
print
(
'
Save output
'
)
outputlist
=
[
'
FA
'
,
'
AD
'
,
'
MD
'
,
'
MODE
'
,
'
RD
'
,
'
SPHERICITY
'
,
'
LINEARITY
'
,
'
PLANARITY
'
,
'
F
'
]
for
o
in
outputlist
:
img
=
Image
(
getattr
(
fwdtifit
,
o
.
lower
()),
header
=
header
)
img
.
save
(
f
'
{
args
.
out
}
_
{
o
}
'
)
if
args
.
verbose
:
print
(
'
Done
'
)
Loading