Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
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
FSL
fslpy
Commits
a339d71e
Commit
a339d71e
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
ENH: convert_x5 updated to handle non-linear. Nothing is tested
parent
6154a5b6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/scripts/fsl_convert_x5.py
+73
-21
73 additions, 21 deletions
fsl/scripts/fsl_convert_x5.py
with
73 additions
and
21 deletions
fsl/scripts/fsl_convert_x5.py
+
73
−
21
View file @
a339d71e
...
@@ -24,43 +24,100 @@ def parseArgs(args):
...
@@ -24,43 +24,100 @@ def parseArgs(args):
parser
=
argparse
.
ArgumentParser
(
'
fsl_convert_x5
'
)
parser
=
argparse
.
ArgumentParser
(
'
fsl_convert_x5
'
)
subparsers
=
parser
.
add_subparsers
(
dest
=
'
ctype
'
)
subparsers
=
parser
.
add_subparsers
(
dest
=
'
ctype
'
)
flirt
=
subparsers
.
add_parser
(
'
flirt
'
)
flirt
=
subparsers
.
add_parser
(
'
flirt
'
)
fnirt
=
subparsers
.
add_parser
(
'
fnirt
'
)
flirt
.
add_argument
(
'
input
'
)
flirt
.
add_argument
(
'
input
'
)
flirt
.
add_argument
(
'
output
'
)
flirt
.
add_argument
(
'
output
'
)
flirt
.
add_argument
(
'
-s
'
,
'
--source
'
)
flirt
.
add_argument
(
'
-s
'
,
'
--source
'
)
flirt
.
add_argument
(
'
-r
'
,
'
--reference
'
)
flirt
.
add_argument
(
'
-r
'
,
'
--reference
'
)
flirt
.
add_argument
(
'
-if
'
,
'
--input_format
'
,
choices
=
(
'
x5
'
,
'
mat
'
))
flirt
.
add_argument
(
'
-if
'
,
'
--input_format
'
,
choices
=
(
'
x5
'
,
'
mat
'
))
flirt
.
add_argument
(
'
-of
'
,
'
--output_format
'
,
choices
=
(
'
x5
'
,
'
mat
'
))
flirt
.
add_argument
(
'
-of
'
,
'
--output_format
'
,
choices
=
(
'
x5
'
,
'
mat
'
))
intype
=
fnirt
.
add_mutually_exclusive_group
()
outtype
=
fnirt
.
add_mutually_exclusive_group
()
fnirt
.
add_argument
(
'
input
'
)
fnirt
.
add_argument
(
'
output
'
)
fnirt
.
add_argument
(
'
-s
'
,
'
--source
'
)
fnirt
.
add_argument
(
'
-r
'
,
'
--reference
'
)
fnirt
.
add_argument
(
'
-if
'
,
'
--input_format
'
,
choices
=
(
'
x5
'
,
'
nii
'
))
fnirt
.
add_argument
(
'
-of
'
,
'
--output_format
'
,
choices
=
(
'
x5
'
,
'
nii
'
))
intype
.
add_argument
(
'
-ai
'
,
'
--absin
'
,
action
=
'
store_const
'
,
const
=
'
absolute
'
,
dest
=
'
inDispType
'
)
intype
.
add_argument
(
'
-ri
'
,
'
--relin
'
,
action
=
'
store_const
'
,
const
=
'
relative
'
,
dest
=
'
inDispType
'
)
outtype
.
add_argument
(
'
-ao
'
,
'
--absout
'
,
action
=
'
store_const
'
,
const
=
'
absolute
'
,
dest
=
'
outDispType
'
)
outtype
.
add_argument
(
'
-ro
'
,
'
--relout
'
,
action
=
'
store_const
'
,
const
=
'
relative
'
,
dest
=
'
outDispType
'
)
args
=
parser
.
parse_args
(
args
)
args
=
parser
.
parse_args
(
args
)
def
getfmt
(
fname
):
if
args
.
ctype
is
None
:
parser
.
print_help
()
sys
.
exit
(
0
)
def
getfmt
(
arg
,
fname
):
ext
=
op
.
splitext
(
fname
)[
1
]
ext
=
op
.
splitext
(
fname
)[
1
]
if
ext
not
in
(
'
.x5
'
,
'
.mat
'
):
if
ext
in
(
'
.mat
'
,
'
.x5
'
):
raise
argparse
.
ArgumentError
(
'
Could not infer format from
'
return
ext
[
1
:]
'
filename: {}
'
.
format
(
args
.
input
))
if
fslimage
.
looksLikeImage
(
fslimage
.
fixExt
(
fname
)):
return
ext
[
1
:]
return
'
nii
'
parser
.
error
(
'
Could not infer format from
'
'
filename: {}
'
.
format
(
args
.
input
))
if
args
.
ctype
==
'
flirt
'
:
if
args
.
input_format
is
None
:
args
.
input_format
=
getfmt
(
'
input
'
,
args
.
input
)
if
args
.
input_format
is
None
:
args
.
input_format
=
getfmt
(
args
.
input
)
if
args
.
output_format
is
None
:
args
.
output_format
=
getfmt
(
'
output
'
,
args
.
output
)
if
args
.
output_format
is
None
:
args
.
output_format
=
getfmt
(
args
.
output
)
return
args
return
args
def
flirtToX5
(
args
):
def
flirtToX5
(
args
):
src
=
fslimage
.
Image
(
args
.
source
)
src
=
fslimage
.
Image
(
args
.
source
,
loadData
=
False
)
ref
=
fslimage
.
Image
(
args
.
reference
)
ref
=
fslimage
.
Image
(
args
.
reference
,
loadData
=
False
)
xform
=
transform
.
readFlirt
(
args
.
input
)
xform
=
transform
.
readFlirt
(
args
.
input
)
transform
.
writeFlirtX5
(
args
.
output
,
xform
,
src
,
ref
)
xform
=
transform
.
fromFlirt
(
xform
,
src
,
ref
,
'
world
'
,
'
world
'
)
transform
.
writeLinearX5
(
args
.
output
,
xform
,
src
,
ref
)
def
X5ToFlirt
(
args
):
def
X5ToFlirt
(
args
):
xform
,
src
,
ref
=
transform
.
read
Flirt
X5
(
args
.
input
)
xform
,
src
,
ref
=
transform
.
read
Linear
X5
(
args
.
input
)
xform
=
transform
.
toFlirt
(
xform
,
src
,
ref
,
'
world
'
,
'
world
'
)
xform
=
transform
.
toFlirt
(
xform
,
src
,
ref
,
'
world
'
,
'
world
'
)
transform
.
writeFlirt
(
xform
,
args
.
output
)
transform
.
writeFlirt
(
xform
,
args
.
output
)
def
fnirtToX5
(
args
):
src
=
fslimage
.
Image
(
args
.
source
,
loadData
=
False
)
ref
=
fslimage
.
Image
(
args
.
reference
,
loadData
=
False
)
field
=
transform
.
readFnirt
(
args
.
input
,
src
=
src
,
ref
=
ref
,
dispType
=
args
.
inDispType
)
field
=
transform
.
fromFnirt
(
field
,
'
world
'
,
'
world
'
)
transform
.
writeNonLinearX5
(
args
.
output
,
field
)
def
X5ToFnirt
(
args
):
field
=
transform
.
readNonLinearX5
(
args
.
input
)
field
=
transform
.
toFnirt
(
field
,
'
world
'
,
'
world
'
)
transform
.
writeFnirt
(
field
,
args
.
output
)
def
doFlirt
(
args
):
infmt
=
args
.
input_format
outfmt
=
args
.
output_format
if
(
infmt
,
outfmt
)
==
(
'
x5
'
,
'
mat
'
):
X5ToFlirt
(
args
)
elif
(
infmt
,
outfmt
)
==
(
'
mat
'
,
'
x5
'
):
flirtToX5
(
args
)
else
:
shutil
.
copy
(
args
.
input
,
args
.
output
)
def
doFnirt
(
args
):
infmt
=
args
.
input_format
outfmt
=
args
.
output_format
if
(
infmt
,
outfmt
)
==
(
'
x5
'
,
'
nii
'
):
X5ToFnirt
(
args
)
elif
(
infmt
,
outfmt
)
==
(
'
nii
'
,
'
x5
'
):
fnirtToX5
(
args
)
else
:
shutil
.
copy
(
args
.
input
,
args
.
output
)
def
main
(
args
=
None
):
def
main
(
args
=
None
):
if
args
is
None
:
if
args
is
None
:
...
@@ -69,13 +126,8 @@ def main(args=None):
...
@@ -69,13 +126,8 @@ def main(args=None):
args
=
parseArgs
(
args
)
args
=
parseArgs
(
args
)
ctype
=
args
.
ctype
ctype
=
args
.
ctype
if
ctype
==
'
flirt
'
:
if
ctype
==
'
flirt
'
:
doFlirt
(
args
)
infmt
=
args
.
input_format
elif
ctype
==
'
fnirt
'
:
doFnirt
(
args
)
outfmt
=
args
.
output_format
if
(
infmt
,
outfmt
)
==
(
'
x5
'
,
'
mat
'
):
X5ToFlirt
(
args
)
elif
(
infmt
,
outfmt
)
==
(
'
mat
'
,
'
x5
'
):
flirtToX5
(
args
)
else
:
shutil
.
copy
(
args
.
input
,
args
.
output
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment