Ejemplo n.º 1
0
def get_dcm_slice_timing(dicom_files):
# From Satrajit Ghosh's code at: https://github.com/satra/nipype/blob/enh/restingwf/examples/rsfmri_preprocessing.py#L47
    from dcmstack.extract import default_extractor
    from dicom import read_file
    from nipype.utils.filemanip import filename_to_list

    meta = default_extractor(read_file(filename_to_list(dicom_files)[0],
                                       stop_before_pixels=True,
                                       force=True))
    return (meta['RepetitionTime'] / 1000., meta['CsaImage.MosaicRefAcqTimes'],
            meta['SpacingBetweenSlices'])
Ejemplo n.º 2
0
def get_info(dicom_files):
	"""Given a Siemens dicom file return metadata
	Returns
	-------
	Slice Acquisition Times
	"""
	meta = default_extractor(read_file(filename_to_list(dicom_files)[0],
		                       stop_before_pixels=True,
		                       force=True))
	# returning STA in seconds...
	return meta['CsaImage.MosaicRefAcqTimes']  
def get_info(dicom_files):
    """Given a Siemens dicom file return metadata

    Returns
    -------
    RepetitionTime
    Slice Acquisition Times
    Spacing between slices
    """
    meta = default_extractor(read_file(filename_to_list(dicom_files)[0], stop_before_pixels=True, force=True))
    return (meta["RepetitionTime"] / 1000.0, meta["CsaImage.MosaicRefAcqTimes"], meta["SpacingBetweenSlices"])
Ejemplo n.º 4
0
def get_info(dicom_files):
    """Given a Siemens dicom file return metadata
	Returns
	-------
	Slice Acquisition Times
	"""
    meta = default_extractor(
        read_file(filename_to_list(dicom_files)[0],
                  stop_before_pixels=True,
                  force=True))
    # returning STA in seconds...
    return meta['CsaImage.MosaicRefAcqTimes']
Ejemplo n.º 5
0
def get_info(dicom_files):
    """Given a Siemens dicom file return metadata

    Returns
    -------
    RepetitionTime
    Slice Acquisition Times
    Spacing between slices
    """
    meta = default_extractor(read_file(filename_to_list(dicom_files)[0],
                                       stop_before_pixels=True,
                                       force=True))
    return (meta['RepetitionTime'] / 1000., meta['CsaImage.MosaicRefAcqTimes'],
            meta['SpacingBetweenSlices'])
def get_info(dicom_files):
    from dcmstack.extract import default_extractor
    """Given a Siemens dicom file return metadata

    Returns
    -------
    RepetitionTime
    Slice Acquisition Times
    Spacing between slices
    """
    meta = default_extractor(read_file(filename_to_list(dicom_files)[0],
                                       stop_before_pixels=True,
                                       force=True))
    return (meta['RepetitionTime']/1000., meta['CsaImage.MosaicRefAcqTimes'],
            meta['SpacingBetweenSlices'])
Ejemplo n.º 7
0
def get_info(dicom_files):
    """Given a Siemens dicom file return metadata

    Returns
    -------
    RepetitionTime
    Slice Acquisition Times
    Spacing between slices
    """
    try:
        from dcmstack.extract import default_extractor
    except:
        raise ImportError("To use this function install dcmstack: pip install "
                          "git+https://github.com/moloney/dcmstack.git@c12d27d2c802d75a33ad70110124500a83e851ee#egg=dcmstack")

    meta = default_extractor(read_file(filename_to_list(dicom_files)[0],
                                       stop_before_pixels=True,
                                       force=True))
    return (meta['RepetitionTime'] / 1000., meta['CsaImage.MosaicRefAcqTimes'],
            meta['SpacingBetweenSlices'])
Ejemplo n.º 8
0
    def fast_retrieve_dicom(self, path, meta=None):
        # add_dcm takes a lot of time if we have to reexamine metadata everytime
        # so we copy metadata if we're in the same volume of a time series

        dcm = self.client.retrieve_dicom(path)
        try:
            #get the volume number
            tpid = dcm[(0x0020, 0x0100)].value
        except KeyError:
            # then were not looking at a time series
            return (dcm, None)

        #otherwise
        if tpid != self.tpid:
            # then we're in a new volume
            meta = default_extractor(dcm)
        else:
            #we're in the same volume, so use old meta:
            meta = self.volumizer._get_meta(dcm, meta)

        return (dcm, meta)
Ejemplo n.º 9
0
def get_info(dicom_file):
    """Given a Siemens dicom file return metadata
    Returns
    -------
    RepetitionTime
    Slice Acquisition Times
    Spacing between slices
    """
    from dcmstack.extract import default_extractor
    import numpy as np
    from dicom import read_file
    from nipype.utils.filemanip import filename_to_list

    meta = default_extractor(read_file(filename_to_list(dicom_file)[0], stop_before_pixels=True, force=True))

    TR = meta["RepetitionTime"] / 1000.0
    slice_times_pre = meta["CsaImage.MosaicRefAcqTimes"]
    slice_times = (np.array(slice_times_pre) / 1000.0).tolist()
    slice_thickness = meta["SpacingBetweenSlices"]

    return TR, slice_times, slice_thickness
Ejemplo n.º 10
0
    def fast_retrieve_dicom(self, path, meta=None):
        # add_dcm takes a lot of time if we have to reexamine metadata everytime
        # so we copy metadata if we're in the same volume of a time series

        dcm = self.client.retrieve_dicom(path)
        try:
            #get the volume number
            tpid = dcm[(0x0020, 0x0100)].value
        except KeyError:
            # then were not looking at a time series
            return(dcm, None)

        #otherwise
        if tpid != self.tpid:
            # then we're in a new volume
            meta = default_extractor(dcm)
        else:
            #we're in the same volume, so use old meta:
            meta = self.volumizer._get_meta(dcm, meta)

        return(dcm, meta)
Ejemplo n.º 11
0
def get_info(dicom_file):
    """Given a Siemens dicom file return metadata
    Returns
    -------
    RepetitionTime
    Slice Acquisition Times
    Spacing between slices
    """
    from dcmstack.extract import default_extractor
    import numpy as np
    from dicom import read_file
    from nipype.utils.filemanip import filename_to_list
    
    meta = default_extractor(read_file(filename_to_list(dicom_file)[0],
                                       stop_before_pixels=True,
                                       force=True))
    
    TR=meta['RepetitionTime']/1000.
    slice_times_pre=meta['CsaImage.MosaicRefAcqTimes']
    slice_times = (np.array(slice_times_pre)/1000.).tolist()
    slice_thickness = meta['SpacingBetweenSlices']
    
    return TR, slice_times, slice_thickness
Ejemplo n.º 12
0
    def assemble_volume(self, slices):
        """Put each dicom slice together into a nibabel nifti image object."""
        # Build a DicomStack from each of the slices
        tic = time.time()

        meta = default_extractor(slices[0])

        stack = DicomStack()
        for f in slices:
            # without new_meta, this takes 99% of time in this function by
            # wasting cycles on looking up redundant data.
            new_meta = self._get_meta(f, meta)
            stack.add_dcm(f, new_meta)

        # Convert into a Nibabel Nifti object
        nii_img = stack.to_nifti(voxel_order="")

        # Build the volume dictionary we will put in the dicom queue
        dcm = slices[0]
        exam, series, acquisition = self.dicom_esa(dcm)
        volume = dict(
            exam=exam,
            series=series,
            acquisition=acquisition,
            patient_id=dcm.PatientID,
            series_description=dcm.SeriesDescription,
            tr=float(dcm.RepetitionTime) / 1000,
            ntp=float(dcm.NumberOfTemporalPositions),
            image=nii_img,
        )
        time_it(tic, "Assembled a volume", level='info')

        if self.keep_vols:
            self.assembled_volumes.append(volume)
        self.last_assembled_time = time.time()
        return volume
Ejemplo n.º 13
0
    def assemble_volume(self, slices):
        """Put each dicom slice together into a nibabel nifti image object."""
        # Build a DicomStack from each of the slices
        tic = time.time()

        meta = default_extractor(slices[0])

        stack = DicomStack()
        for f in slices:
            # without new_meta, this takes 99% of time in this function by
            # wasting cycles on looking up redundant data.
            new_meta = self._get_meta(f, meta)
            stack.add_dcm(f, new_meta)

        # Convert into a Nibabel Nifti object
        nii_img = stack.to_nifti(voxel_order="")

        # Build the volume dictionary we will put in the dicom queue
        dcm = slices[0]
        exam, series, acquisition = self.dicom_esa(dcm)
        volume = dict(
            exam=exam,
            series=series,
            acquisition=acquisition,
            patient_id=dcm.PatientID,
            series_description=dcm.SeriesDescription,
            tr=float(dcm.RepetitionTime) / 1000,
            ntp=float(dcm.NumberOfTemporalPositions),
            image=nii_img,
        )
        time_it(tic, "Assembled a volume", level='info')

        if self.keep_vols:
            self.assembled_volumes.append(volume)
        self.last_assembled_time = time.time()
        return volume
Ejemplo n.º 14
0
from dcmstack.extract import default_extractor
import pydicom
import os

data_path = '/media/charesti-start/data/irsa-fmri/dicom/CBU101295/20100930_101706/Series_003_CBU_EPI_BOLD_216/'

dicom_file = os.path.join(
    data_path, '1.3.12.2.1107.5.2.32.35119.2010093010310825996437574.dcm')

ds = pydicom.dcmread(dicom_file)

meta = default_extractor(
    ds)

st_times = np.asarray(meta['CsaImage.MosaicRefAcqTimes'])/1000