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
a5b4b5b4
Commit
a5b4b5b4
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
New method on Nifti class, to retrieve strings from nifti headers (moved here
from fsleyes OverlayInfoPanel)
parent
66b1d7ca
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/data/image.py
+28
-0
28 additions, 0 deletions
fsl/data/image.py
with
28 additions
and
0 deletions
fsl/data/image.py
+
28
−
0
View file @
a5b4b5b4
...
...
@@ -34,6 +34,7 @@ and file names:
import
os
import
os.path
as
op
import
string
import
logging
import
six
...
...
@@ -290,6 +291,33 @@ class Nifti(notifier.Notifier):
return
origShape
,
shape
,
pixdims
def
strval
(
self
,
key
):
"""
Returns the specified NIFTI header field, converted to a python
string, correctly null-terminated, and with non-printable characters
removed.
This method is used to sanitise some NIFTI header fields. The default
Python behaviour for converting a sequence of bytes to a string is to
strip all termination characters (bytes with value of ``0x00``) from
the end of the sequence.
This default behaviour does not handle the case where a sequence of
bytes which did contain a long string is subsequently overwritten with
a shorter string - the short string will be terminated, but that
termination character will be followed by the remainder of the
original string.
"""
val
=
self
.
header
[
key
]
try
:
val
=
bytes
(
val
).
partition
(
b
'
\0
'
)[
0
]
except
:
val
=
bytes
(
val
)
val
=
val
.
decode
(
'
ascii
'
)
return
''
.
join
([
c
for
c
in
val
if
c
in
string
.
printable
])
@property
def
niftiVersion
(
self
):
"""
Returns the NIFTI file version:
...
...
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