Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD 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
Evan Edmond
fslpy
Commits
ca9022b9
Commit
ca9022b9
authored
3 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
RF: Make sure name/dataSource are set the same, regardless of whether image is
created from a str or Path obj
parent
f3f3d6a2
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
+29
-33
29 additions, 33 deletions
fsl/data/image.py
with
29 additions
and
33 deletions
fsl/data/image.py
+
29
−
33
View file @
ca9022b9
...
...
@@ -32,22 +32,21 @@ and file names:
"""
import
os
import
os.path
as
op
import
itertools
as
it
import
json
import
string
import
logging
import
tempfile
import
six
import
numpy
as
np
import
os
import
os.path
as
op
import
itertools
as
it
import
json
import
string
import
logging
import
tempfile
from
pathlib
import
Path
from
typing
import
Union
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
...
...
@@ -58,6 +57,10 @@ import fsl.data.constants as constants
import
fsl.data.imagewrapper
as
imagewrapper
PathLike
=
Union
[
str
,
Path
]
ImageSource
=
Union
[
PathLike
,
nib
.
Nifti1Image
,
np
.
ndarray
,
'
Image
'
]
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -993,21 +996,21 @@ class Image(Nifti):
def
__init__
(
self
,
image
,
name
=
None
,
header
=
None
,
xform
=
None
,
loadData
=
True
,
calcRange
=
True
,
threaded
=
False
,
dataSource
=
None
,
loadMeta
=
False
,
image
:
ImageSource
,
name
:
str
=
None
,
header
:
nib
.
Nifti1Header
=
None
,
xform
:
np
.
ndarray
=
None
,
loadData
:
bool
=
True
,
calcRange
:
bool
=
True
,
threaded
:
bool
=
False
,
dataSource
:
PathLike
=
None
,
loadMeta
:
bool
=
False
,
**
kwargs
):
"""
Create 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 a Path object pointing to an image file, or a
:mod:`numpy` array, or a :mod:`nibabel` image object,
or a Path object pointing to an image file, or a
:mod:`numpy` array, or a :mod:`nibabel` image object,
or an ``Image`` object.
:arg name: A name for the image.
...
...
@@ -1086,16 +1089,11 @@ class Image(Nifti):
header
.
set_qform
(
xform
,
code
=
qform
)
# The image parameter may be the name of an image file
if
isinstance
(
image
,
six
.
string_types
):
if
isinstance
(
image
,
(
str
,
Path
)
):
image
=
op
.
abspath
(
addExt
(
image
))
nibImage
=
nib
.
load
(
image
,
**
kwargs
)
dataSource
=
image
saved
=
True
# The image parameter may be a Path object pointing to an image file
elif
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
...
...
@@ -1141,15 +1139,13 @@ class Image(Nifti):
nibImage
=
image
# Figure out the name of this image, if
# it has not been
been
explicitly passed in
# it has not been explicitly passed in
if
name
is
None
:
# If this image was loaded
# from disk, use the file name.
if
isinstance
(
image
,
six
.
string_types
):
if
isinstance
(
image
,
(
str
,
Path
)
):
name
=
removeExt
(
op
.
basename
(
image
))
elif
isinstance
(
image
,
Path
):
name
=
image
.
name
# Or the image was created from a numpy array
elif
isinstance
(
image
,
np
.
ndarray
):
...
...
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