Skip to content
Snippets Groups Projects
Commit 18bb892c authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Little adjustments

parent e8ea00dc
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ wrappers around functionality provided by Chris Rorden's ``dcm2niix`` program: ...@@ -15,7 +15,7 @@ wrappers around functionality provided by Chris Rorden's ``dcm2niix`` program:
:nosignatures: :nosignatures:
scanDir scanDir
loadNifti loadSeries
.. note:: These functions will not work if an executable called ``dcm2niix`` .. note:: These functions will not work if an executable called ``dcm2niix``
cannot be found. cannot be found.
...@@ -29,6 +29,8 @@ import subprocess as sp ...@@ -29,6 +29,8 @@ import subprocess as sp
import glob import glob
import json import json
import nibabel as nib
import fsl.utils.tempdir as tempdir import fsl.utils.tempdir as tempdir
import fsl.data.image as fslimage import fsl.data.image as fslimage
...@@ -41,13 +43,13 @@ class DicomImage(fslimage.Image): ...@@ -41,13 +43,13 @@ class DicomImage(fslimage.Image):
transformation. Additional DICOM metadata may be accessed via TODO transformation. Additional DICOM metadata may be accessed via TODO
""" """
def __init__(self, image, meta): def __init__(self, image, meta, *args, **kwargs):
"""Create a ``DicomImage``. """Create a ``DicomImage``.
:arg image: Passed through to :meth:`.Image.__init__`. :arg image: Passed through to :meth:`.Image.__init__`.
:arg meta: Dictionary containing DICOM meta-data. :arg meta: Dictionary containing DICOM meta-data.
""" """
fslimage.Image.__init__(self, image) fslimage.Image.__init__(self, image, *args, **kwargs)
self.__meta = meta self.__meta = meta
...@@ -94,7 +96,7 @@ def scanDir(dcmdir): ...@@ -94,7 +96,7 @@ def scanDir(dcmdir):
with tempdir.tempdir() as td: 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')) files = glob.glob(op.join(td, '*.json'))
...@@ -117,7 +119,7 @@ def scanDir(dcmdir): ...@@ -117,7 +119,7 @@ def scanDir(dcmdir):
return series return series
def loadNifti(series): def loadSeries(series):
"""Takes a DICOM series meta data dictionary, as returned by """Takes a DICOM series meta data dictionary, as returned by
:func:`scanDir`, and loads the associated data as one or more NIFTI :func:`scanDir`, and loads the associated data as one or more NIFTI
images. images.
...@@ -130,11 +132,14 @@ def loadNifti(series): ...@@ -130,11 +132,14 @@ def loadNifti(series):
dcmdir = series['DicomDir'] dcmdir = series['DicomDir']
snum = series['SeriesNumber'] 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: 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 files] return [DicomImage(i, series, name=desc) for i in images]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment