Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Evan Edmond
fslpy
Commits
cf1b038a
Commit
cf1b038a
authored
Mar 30, 2021
by
Evan Edmond
Browse files
ENH: accept pathlib objects for Image
parent
35fae740
Changes
1
Hide whitespace changes
Inline
Side-by-side
fsl/data/image.py
View file @
cf1b038a
...
...
@@ -46,6 +46,8 @@ import numpy as np
import
nibabel
as
nib
import
nibabel.fileslice
as
fileslice
from
pathlib
import
Path
import
fsl.utils.meta
as
meta
import
fsl.transform.affine
as
affine
import
fsl.utils.notifier
as
notifier
...
...
@@ -1088,6 +1090,11 @@ class Image(Nifti):
nibImage
=
nib
.
load
(
image
,
**
kwargs
)
dataSource
=
image
saved
=
True
# The image parameter may be the name of an image file
if
isinstance
(
image
,
Path
):
nibImage
=
nib
.
load
(
image
,
**
kwargs
)
dataSource
=
str
(
image
)
saved
=
True
# Or a numpy array - we wrap it in a nibabel image,
# with an identity transformation (each voxel maps
...
...
@@ -1140,6 +1147,8 @@ class Image(Nifti):
# from disk, use the file name.
if
isinstance
(
image
,
six
.
string_types
):
name
=
removeExt
(
op
.
basename
(
image
))
if
isinstance
(
image
,
Path
):
name
=
image
.
name
# Or the image was created from a numpy array
elif
isinstance
(
image
,
np
.
ndarray
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment