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
78901622
Commit
78901622
authored
10 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Name/xform can be set in Image constructor (for images created in
memory). Bugfix to ImageList.insert
parent
e153f39a
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
+22
-10
22 additions, 10 deletions
fsl/data/image.py
with
22 additions
and
10 deletions
fsl/data/image.py
+
22
−
10
View file @
78901622
...
@@ -159,8 +159,14 @@ class Image(props.HasProperties):
...
@@ -159,8 +159,14 @@ class Image(props.HasProperties):
to the image data must be via the :meth:`applyChange` method.
to the image data must be via the :meth:`applyChange` method.
"""
"""
saved
=
props
.
Boolean
(
default
=
False
)
"""
A read only property (not enforced) which is ``True`` if the image,
as stored in memory, is saved to disk, ``False`` otherwise.
"""
def
__init__
(
self
,
image
):
def
__init__
(
self
,
image
,
xform
=
None
,
name
=
None
):
"""
Initialise an Image object with the given image data or file name.
"""
Initialise an Image object with the given image data or file name.
:arg image: A string containing the name of an image file to load, or
:arg image: A string containing the name of an image file to load, or
...
@@ -182,21 +188,29 @@ class Image(props.HasProperties):
...
@@ -182,21 +188,29 @@ class Image(props.HasProperties):
self
.
tempFile
=
nibImage
.
get_filename
()
self
.
tempFile
=
nibImage
.
get_filename
()
else
:
else
:
self
.
name
=
op
.
basename
(
self
.
imageFile
)
self
.
name
=
op
.
basename
(
self
.
imageFile
)
self
.
saved
=
True
# Or a numpy array - we wrap it in a nibabel image,
# Or a numpy array - we wrap it in a nibabel image,
# with an identity transformation (each voxel maps
# with an identity transformation (each voxel maps
# to 1mm^3 in real world space)
# to 1mm^3 in real world space)
elif
isinstance
(
image
,
np
.
ndarray
):
elif
isinstance
(
image
,
np
.
ndarray
):
if
xform
is
None
:
xform
=
np
.
identity
(
4
)
if
name
is
None
:
name
=
'
Numpy array
'
self
.
nibImage
=
nib
.
nifti1
.
Nifti1Image
(
image
,
np
.
identity
(
4
)
)
self
.
nibImage
=
nib
.
nifti1
.
Nifti1Image
(
image
,
xform
)
self
.
name
=
'
Numpy array
'
self
.
name
=
name
self
.
tempFile
=
None
self
.
tempFile
=
None
self
.
imageFile
=
None
self
.
imageFile
=
None
# otherwise, we assume that it is a nibabel image
# otherwise, we assume that it is a nibabel image
else
:
else
:
if
name
is
None
:
name
=
'
Nibabel image
'
self
.
nibImage
=
image
self
.
nibImage
=
image
self
.
name
=
'
Nibabel image
'
self
.
name
=
name
self
.
tempFile
=
None
self
.
tempFile
=
None
self
.
imageFile
=
None
self
.
imageFile
=
None
...
@@ -206,8 +220,6 @@ class Image(props.HasProperties):
...
@@ -206,8 +220,6 @@ class Image(props.HasProperties):
self
.
voxToWorldMat
=
np
.
array
(
self
.
nibImage
.
get_affine
())
self
.
voxToWorldMat
=
np
.
array
(
self
.
nibImage
.
get_affine
())
self
.
worldToVoxMat
=
transform
.
invert
(
self
.
voxToWorldMat
)
self
.
worldToVoxMat
=
transform
.
invert
(
self
.
voxToWorldMat
)
self
.
changed
=
False
self
.
data
.
flags
.
writeable
=
False
self
.
data
.
flags
.
writeable
=
False
if
len
(
self
.
shape
)
<
3
or
len
(
self
.
shape
)
>
4
:
if
len
(
self
.
shape
)
<
3
or
len
(
self
.
shape
)
>
4
:
...
@@ -252,8 +264,8 @@ class Image(props.HasProperties):
...
@@ -252,8 +264,8 @@ class Image(props.HasProperties):
data
.
flags
.
writeable
=
False
data
.
flags
.
writeable
=
False
raise
raise
self
.
changed
=
True
self
.
data
=
data
self
.
data
=
data
self
.
saved
=
False
def
__hash__
(
self
):
def
__hash__
(
self
):
...
@@ -484,7 +496,7 @@ class ImageList(props.HasProperties):
...
@@ -484,7 +496,7 @@ class ImageList(props.HasProperties):
def
extend
(
self
,
iterable
):
return
self
.
images
.
extend
(
iterable
)
def
extend
(
self
,
iterable
):
return
self
.
images
.
extend
(
iterable
)
def
pop
(
self
,
index
=-
1
):
return
self
.
images
.
pop
(
index
)
def
pop
(
self
,
index
=-
1
):
return
self
.
images
.
pop
(
index
)
def
move
(
self
,
from_
,
to
):
return
self
.
images
.
move
(
from_
,
to
)
def
move
(
self
,
from_
,
to
):
return
self
.
images
.
move
(
from_
,
to
)
def
insert
(
self
,
index
,
item
):
return
self
.
images
.
insert
All
(
index
,
def
insert
(
self
,
index
,
item
):
return
self
.
images
.
insert
(
index
,
item
)
item
)
def
insertAll
(
self
,
index
,
items
):
return
self
.
images
.
insertAll
(
index
,
def
insertAll
(
self
,
index
,
items
):
return
self
.
images
.
insertAll
(
index
,
items
)
items
)
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