Useful links for DTI processing

5 minute read

DICOM headers

DICOM is usually the data format downloaded form the scanner or the PACS system. (PACS system is an archiving system widely used in hospitals that data can be transdered from the scanner into the system via Network). DICOM is saved as in a 2D protocol. A lot of important infomation is saved in the DICOM header in order to get the 3D (T1 anatonmy scan) or 4D (fMRI or DTI) NfiTi images. Below lists some important header tags that are important:

  1. The number of slices:
    • This tag could be tested by loading all of the files and then counting the slices for 3D images.
    • For 4d sequences like DTI and fMRI, where you have a set of volumes acquired many times, you also need to look at the DICOM SliceLocation field, which tells you the slice’s position in the volume (in physical space units). The number of unique slice locations is the ‘official’ DICOM indication of the number of slices.
    • The number of direction is defined by the gradient file code. So, for grad file code 865, the number of directions is 30. This is the total number of non-collinear directions you used, not including the b0s. If Bob defined the protocol, the number of directions can be guessed from the protocol name stored in the header (info.SeriesDescription). MORE IMPORTANTLY – we should never have to specify this, preprocessing script should derive this information from the grad file.
    • Copied from Number of slices section
  2. qform and sform: qform is used to transfer the image from the voxel space (i,j,k) to scanner space (x,y,z). sform is an affine transform between coordinate systems. For more information on how these two values are used in the transformation, please check nifti1.h header documentation.

  3. b-value:
    • This is a tag specifically for DTI data that reflects the strength and timing of the gradients used to generate diffusion-weighted images.
    • It depends on the strength, duration, and spacing of these pulsed gradients. A larger b-value is achieved with increasing the gradient amplitude and duration and by widening the interval between gradient pulses.
    • The value of b is selected by the operator prior to imaging. Larger b shows progressively more diffusion weighting but also more noise. Mechanical vibration artifacts may also be a problem as b-values are increased.  
    • As a practical matter, most routine clinical DWI currently use b-values between 0 and 1000, with slightly lower values being used outside the central nervous system. 
    • Copied from mriquestions
  4. Number Of Images In Mosaic: Siemens stores 3D images in a 2D grid where at each grid point, there is another 2D image. So the number of mosaic field is used to reconstruct the 3D image from this 2D grid. https://nipy.org/nibabel/dicom/dicom_mosaic.html

  5. Toolbox MIPAV: This is a C toolbox that can be uses to anonymize DICOM files and view DICOM header in a GUI.

  6. Toolbox pydicom: This is a python package and can edits DICOM header. Some examples are:
    # add new tag
    ds = pydicom.dcmread(fname)
    ds.add_new(0x0019100A, 'US', 37)
    ds.save_as(fname)
    # Change tag
    ds.Manufacture='x' # change this tag to 'x'
    

    Notes: Use the code above, I added “Number of Mosaic” tag into the dicom. But dcm2niix still cannot read this tag. I am not sure if I add this in a wrong way. And also, I cannot name this new tag. The name of it remains as “private tag”

# Add dictionary
from pydicom.datadict import DicomDictionary, keyword_dict
from pydicom.dataset import Dataset

new_dict_items = {0x0019100A: ('US', '1', "Number Of Images In Mosaic", '', 'NumberOfImagesInMosaic'),}
# Update the dictionary itself
DicomDictionary.update(new_dict_items)
# Update the reverse mapping from name to tag
new_names_dict = dict([(val[4], tag) for tag, val in
                       new_dict_items.items()])
keyword_dict.update(new_names_dict)
# Test that it is working
ds = Dataset()  # or could get one from dcmread, etc
ds.NumberOfImagesInMosaic = 37

Notes: the outcome of this code is the same as the previous one – a new tag named as ‘private tag’ located at (0019, 100a).The change of the dictionary will be gone once exit python.

  1. Value representation: In dicome header, files are saved in bytes. We need to define VR so that the software knows how to read the header.

  2. Header Tags: (http://dicom.nema.org/medical/dicom/current/output/chtml/part06/chapter_6.html)

DTI basics

  1. B0 image and T2 shine-through: The relationship between b-value and the measurement \(S_{DWI}\) is
\[B_{DWI} = B_{0}exp(-bB_{ADC})\]

Because the sequence used for DWI will also cause T2 changes, in practice, we would usually measure a signal with b-value of 0 to account for the T2 shine-through effect and calculate the ADC(apparent diffusion coefficient). Ref1,Ref2

DICOM to NifTi

However, for research purposes, NfiTi (.nii) format is used, so we need to tranform DICOM data to NfiTi. More info see Li et al

dcm2niix can prepare the NifTi data for FSL processing. It also has a GUI intergrated into MicroNGL. It should generate .nii.gz, .bval, and .bvecs files and it makes sure all the images and vectors are in the same coordinate space (the RADIOLOGICAL orientation).

dicm2nii is a Matlab toolbox developed in recent years that is a good resource to learn about DICOM and nii formats.

However, some issue may happen because of the anonymization process. For instance,

  • https://github.com/rordenlab/dcm2niix/issues/275#issuecomment-467114004
  • “I suspect someone was over aggressive in anonymizing the data, and removed all the private tags.”
  • “To determine the number of slices in a mosaic, the DICOM header needs to report the Number Of Images In Mosaic (0019,100A) tag or include include a CSA Image Header Info (0029,1010) tag with the NumberOfImagesInMosaic field”
  • https://www.nitrc.org/forum/forum.php?thread_id=10016&forum_id=4703
  • The link above says how old dcm2nii is estimating the (0019, 100A) when it is missing. But it is very inaccurate.

After the DICOM with all private tags are acquired, problems like missing slices may also be encountered. Take patient Subject 16 from Dr. Zhang for example, I had 1000 DICOM, there are 30 different distances from the first slide (which means there are 30 slides in one volume), however, for one distance, I could have 33 DICOM, and others I could have 34, which means I had missing DICOM files. I suppose to have 34 directions with 30 slices in each volume, but now, I have missing slices for the last volume. To find the slices for the first 33 volume, and discard the last incomplete volume, run dcm2niix -f %t/%s_%p/%4r.dcm -r y ~/Neuro/issuex/ -r means no converting, just rename the files. %t/%s_%p/%4r.dcm means session_date_and_time/series_protocol_name/instance_number(from 0020,0013). More naming rules. After renaming, I can remove all filenames larger than 990 and run the conversion. For the discussion regarding the question, see here.

Steps for DTI processing

  1. Convert DICOM to 4D NifiTi: see the previous section dcm2niix* FSL references, important ones, I need to read those first
    • http://wikis.la.utexas.edu/imagelab/book/how-prepare-your-dti-images-diffusivity-analysis.html
    • https://www.cabi.gatech.edu/CABI/archives/resources/dti-analysis/
    • http://justinblaber.org/brief-introduction-to-dwmri/ I finished the part before step 4.
    • https://www.youtube.com/watch?v=zp0EOuKO3O0&t=2s
  • Some other useful tutorials:
    • Use spm to read DICOM header: https://www.na-mic.org/wiki/NAMIC_Wiki:DTI:DICOM_for_DWI_and_DTI
    • I need to read part 5 of this. https://web.stanford.edu/group/vista/cgi-bin/wiki/index.php/DTI_Preprocessing
  • Also https://web.stanford.edu/group/vista/cgi-bin/wiki/index.php/DTI_Preprocessing_User_Manual
  • A very nice tutorial page with question and answering: https://fsl.fmrib.ox.ac.uk/fslcourse/lectures/practicals/fdt1/index.html
  • A tutorial slide made by FSL people: https://fsl.fmrib.ox.ac.uk/fslcourse/lectures/fdt1.pdf https://www.mccauslandcenter.sc.edu/crnl/tools/advanced-dti