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
a040a24f
Commit
a040a24f
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
RF: Adjust Image.save workflow to ensure image data is synced
parent
d9eb1949
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
+20
-0
20 additions, 0 deletions
fsl/data/image.py
with
20 additions
and
0 deletions
fsl/data/image.py
+
20
−
0
View file @
a040a24f
...
@@ -1204,6 +1204,9 @@ class Image(Nifti):
...
@@ -1204,6 +1204,9 @@ class Image(Nifti):
@property
@property
def
nibImage
(
self
):
def
nibImage
(
self
):
"""
Returns a reference to the ``nibabel`` NIFTI image instance.
"""
Returns a reference to the ``nibabel`` NIFTI image instance.
Note that if the image data has been modified through this ``Image``,
it will be out of sync with what is returned by the ``nibabel`` object,
until a call to :meth:`save` is made.
"""
"""
return
self
.
__nibImage
return
self
.
__nibImage
...
@@ -1387,6 +1390,21 @@ class Image(Nifti):
...
@@ -1387,6 +1390,21 @@ class Image(Nifti):
os
.
close
(
tmphd
)
os
.
close
(
tmphd
)
try
:
try
:
# First of all, the nibabel object won't know
# about any image data modifications, so if
# any have occurred, we need to create a new
# nibabel image using the data managed by the
# imagewrapper, and the old header.
#
# Assuming here that analyze/nifti1/nifti2
# nibabel classes have an __init__ which
# expects (data, affine, header)
if
not
self
.
saveState
:
self
.
__nibImage
=
type
(
self
.
__nibImage
)(
self
[:],
None
,
self
.
header
)
self
.
header
=
self
.
__nibImage
.
header
nib
.
save
(
self
.
__nibImage
,
tmpfname
)
nib
.
save
(
self
.
__nibImage
,
tmpfname
)
# nibabel should close any old
# nibabel should close any old
...
@@ -1395,6 +1413,8 @@ class Image(Nifti):
...
@@ -1395,6 +1413,8 @@ class Image(Nifti):
self
.
__nibImage
=
None
self
.
__nibImage
=
None
self
.
header
=
None
self
.
header
=
None
# Copy to final destination,
# and reload from there
imcp
.
imcp
(
tmpfname
,
filename
,
overwrite
=
True
)
imcp
.
imcp
(
tmpfname
,
filename
,
overwrite
=
True
)
self
.
__nibImage
=
nib
.
load
(
filename
)
self
.
__nibImage
=
nib
.
load
(
filename
)
...
...
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