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
Model registry
Operate
Environments
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
FSL
fslpy
Commits
18bb892c
Commit
18bb892c
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Little adjustments
parent
e8ea00dc
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/dicom.py
+14
-9
14 additions, 9 deletions
fsl/data/dicom.py
with
14 additions
and
9 deletions
fsl/data/dicom.py
+
14
−
9
View file @
18bb892c
...
...
@@ -15,7 +15,7 @@ wrappers around functionality provided by Chris Rorden's ``dcm2niix`` program:
:nosignatures:
scanDir
load
Nifti
load
Series
.. note:: These functions will not work if an executable called ``dcm2niix``
cannot be found.
...
...
@@ -29,6 +29,8 @@ import subprocess as sp
import
glob
import
json
import
nibabel
as
nib
import
fsl.utils.tempdir
as
tempdir
import
fsl.data.image
as
fslimage
...
...
@@ -41,13 +43,13 @@ class DicomImage(fslimage.Image):
transformation. Additional DICOM metadata may be accessed via TODO
"""
def
__init__
(
self
,
image
,
meta
):
def
__init__
(
self
,
image
,
meta
,
*
args
,
**
kwargs
):
"""
Create a ``DicomImage``.
:arg image: Passed through to :meth:`.Image.__init__`.
:arg meta: Dictionary containing DICOM meta-data.
"""
fslimage
.
Image
.
__init__
(
self
,
image
)
fslimage
.
Image
.
__init__
(
self
,
image
,
*
args
,
**
kwargs
)
self
.
__meta
=
meta
...
...
@@ -94,7 +96,7 @@ def scanDir(dcmdir):
with
tempdir
.
tempdir
()
as
td
:
sp
.
call
(
cmd
.
split
())
sp
.
call
(
cmd
.
split
()
,
stdout
=
sp
.
DEVNULL
,
stderr
=
sp
.
DEVNULL
)
files
=
glob
.
glob
(
op
.
join
(
td
,
'
*.json
'
))
...
...
@@ -117,7 +119,7 @@ def scanDir(dcmdir):
return
series
def
load
Nifti
(
series
):
def
load
Series
(
series
):
"""
Takes a DICOM series meta data dictionary, as returned by
:func:`scanDir`, and loads the associated data as one or more NIFTI
images.
...
...
@@ -130,11 +132,14 @@ def loadNifti(series):
dcmdir
=
series
[
'
DicomDir
'
]
snum
=
series
[
'
SeriesNumber
'
]
cmd
=
'
dcm2niix -b n -f %s -z n -o n {}
'
.
format
(
dcmdir
)
desc
=
series
[
'
SeriesDescription
'
]
cmd
=
'
dcm2niix -b n -f %s -z n -o . {}
'
.
format
(
dcmdir
)
with
tempdir
.
tempdir
()
as
td
:
sp
.
call
(
cmd
.
split
())
files
=
glob
.
glob
(
op
.
join
(
td
,
'
{}.nii
'
.
format
(
snum
)))
sp
.
call
(
cmd
.
split
(),
stdout
=
sp
.
DEVNULL
,
stderr
=
sp
.
DEVNULL
)
files
=
glob
.
glob
(
op
.
join
(
td
,
'
{}.nii
'
.
format
(
snum
)))
images
=
[
nib
.
load
(
f
,
mmap
=
False
)
for
f
in
files
]
return
[
DicomImage
(
f
,
series
)
for
f
in
fil
es
]
return
[
DicomImage
(
i
,
series
,
name
=
desc
)
for
i
in
imag
es
]
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