Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Michiel Cottaar
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):
parser
=
argparse
.
ArgumentParser
(
'
fsl_convert_x5
'
)
subparsers
=
parser
.
add_subparsers
(
dest
=
'
ctype
'
)
flirt
=
subparsers
.
add_parser
(
'
flirt
'
)
fnirt
=
subparsers
.
add_parser
(
'
fnirt
'
)
flirt
.
add_argument
(
'
input
'
)
flirt
.
add_argument
(
'
output
'
)
flirt
.
add_argument
(
'
-s
'
,
'
--source
'
)
flirt
.
add_argument
(
'
-r
'
,
'
--reference
'
)
flirt
.
add_argument
(
'
-s
'
,
'
--source
'
)
flirt
.
add_argument
(
'
-r
'
,
'
--reference
'
)
flirt
.
add_argument
(
'
-if
'
,
'
--input_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
)
def
getfmt
(
fname
):
if
args
.
ctype
is
None
:
parser
.
print_help
()
sys
.
exit
(
0
)
def
getfmt
(
arg
,
fname
):
ext
=
op
.
splitext
(
fname
)[
1
]
if
ext
not
in
(
'
.x5
'
,
'
.mat
'
):
raise
argparse
.
ArgumentError
(
'
Could not infer format from
'
'
filename: {}
'
.
format
(
args
.
input
))
return
ext
[
1
:]
if
ext
in
(
'
.mat
'
,
'
.x5
'
):
return
ext
[
1
:]
if
fslimage
.
looksLikeImage
(
fslimage
.
fixExt
(
fname
)):
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
(
args
.
input
)
if
args
.
output_format
is
None
:
args
.
output_format
=
getfmt
(
args
.
output
)
if
args
.
input_format
is
None
:
args
.
input_format
=
getfmt
(
'
input
'
,
args
.
input
)
if
args
.
output_format
is
None
:
args
.
output_format
=
getfmt
(
'
output
'
,
args
.
output
)
return
args
def
flirtToX5
(
args
):
src
=
fslimage
.
Image
(
args
.
source
)
ref
=
fslimage
.
Image
(
args
.
reference
)
src
=
fslimage
.
Image
(
args
.
source
,
loadData
=
False
)
ref
=
fslimage
.
Image
(
args
.
reference
,
loadData
=
False
)
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
):
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
'
)
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
):
if
args
is
None
:
...
...
@@ -69,13 +126,8 @@ def main(args=None):
args
=
parseArgs
(
args
)
ctype
=
args
.
ctype
if
ctype
==
'
flirt
'
:
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
)
if
ctype
==
'
flirt
'
:
doFlirt
(
args
)
elif
ctype
==
'
fnirt
'
:
doFnirt
(
args
)
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