Surgical Planning Laboratoryhttp://www.slicer.org-1-
Brigham and Women’s Hospital
Diffusion Tensor Imaging: from Dicom to Nrrd
Sonia Pujol, Ph.D.Randy Gollub, M.D., Ph.D.
National Alliance for Medical Image Computing
Surgical Planning Laboratoryhttp://www.slicer.org-2-
Brigham and Women’s Hospital
Acknowledgments
National Alliance for Medical Image Computing
NIH U54EB005149
Neuroimage Analysis Center NIH P41RR013218
Laboratory of Mathematics in Imaging, Brigham and Women’s Hospital Thanks to Dr. Gordon Kindlmann
Dartmouth Hitchcock Medical Center Thanks to Dr. Andy Saykin
Surgical Planning Laboratoryhttp://www.slicer.org-3-
Brigham and Women’s Hospital
Raw Data
Goal of the Tutorial
Training on how to convert DICOM DWI data to the Nrrd File format, compatible with Slicer visualization and analysis
Raw DataRaw Data
Nrrd
Header
Dicom HeaderDicom
HeaderDicom HeaderDicom
Header
Raw Data
Surgical Planning Laboratoryhttp://www.slicer.org-4-
Brigham and Women’s Hospital
Overview
• Part 1: DWI data specificity
• Part 2: Nrrd description
• Part 3: Generating Nrrd Files
• Part 4: Working with DICOM DWI training data
• Part 5: Orientation validation within Slicer
Surgical Planning Laboratoryhttp://www.slicer.org-5-
Brigham and Women’s Hospital
Diffusion Weighted Imaging
The signal is dimmer when the direction of the applied gradient is parallel to the principal direction of diffusion.
Diffusion Sensitizing Gradients
Diffusion Weighted Images
Surgical Planning Laboratoryhttp://www.slicer.org-6-
Brigham and Women’s Hospital
Diffusion Weighted Imaging (DWI)
Example: Correlation between the orientation of the 11th gradient and the signal intensity in the Splenium of the Corpus Callosum
Surgical Planning Laboratoryhttp://www.slicer.org-7-
Brigham and Women’s Hospital
Diffusion Weighted Imaging
(Stejskal and Tanner 1965, Basser 1994 )
{Si} represent the signal intensities in presence of the diffusion sensitizing gradients gi
b is the diffusion weighted parameter
Si S0 e b ˆ g iT D ˆ g i
Diffusion Weighted Images
Surgical Planning Laboratoryhttp://www.slicer.org-8-
Brigham and Women’s Hospital
Background• Challenge: Concise and standardized description of
the information contained in DWI data. • Current situation:
– DICOM (Supplement 49) contains information on how to represent b-value and gradient directions of DWI
– However every MR Scanner manufacturer has their own unique way of archiving the relevant image acquisition parameters
– The definition of the coordinate frame of the diffusion gradients is not explicitly recorded in the header
• Proposed Solution: Nrrd format
Surgical Planning Laboratoryhttp://www.slicer.org-9-
Brigham and Women’s Hospital
Which image is correct ?
Surgical Planning Laboratoryhttp://www.slicer.org-10-
Brigham and Women’s Hospital
Which image is correct ?
Surgical Planning Laboratoryhttp://www.slicer.org-11-
Brigham and Women’s Hospital
The left one is correct
Surgical Planning Laboratoryhttp://www.slicer.org-12-
Brigham and Women’s Hospital
Overview
• Part 1: DWI data specificity
• Part 2: Nrrd description
• Part 3: Generating Nrrd Files
• Part 4: Working with DICOM DWI training data
• Part 5: Orientation validation within Slicer
Surgical Planning Laboratoryhttp://www.slicer.org-13-
Brigham and Women’s Hospital
Nearly Raw Raster Data (Nrrd)• The flexible Nrrd format includes a single header file
and image file(s) that can be separate or combined.
• A Nrrd header accurately represents N-dimensional raster information for scientific visualization and medical image processing.
Raw DataRaw Data
Raw DataNrrd
Header+
Surgical Planning Laboratoryhttp://www.slicer.org-14-
Brigham and Women’s Hospital
Nrrd file format
• NA-MIC has developed a robust way of using the Nrrd format to represent DWI volumes
Surgical Planning Laboratoryhttp://www.slicer.org-15-
Brigham and Women’s Hospital
Nrrd file format• DWI data written into Nrrd format with appropriate
parameters can be read into 3D Slicer
Surgical Planning Laboratoryhttp://www.slicer.org-16-
Brigham and Women’s Hospital
Coordinate Frames
Diffusion Weighted Images
Diffusion Sensitizing Gradients
(X,Y,Z) (I,J,K)
Courtesy G.Kindlmann
Courtesy G.Kindlmann
Surgical Planning Laboratoryhttp://www.slicer.org-17-
Brigham and Women’s Hospital
Coordinate Frames
DWI Image Orientation
(I,J,K)
Diffusion Sensitizing Gradients
(X,Y,Z) (X,Y,Z) (I,J,K)
Patient Space
Courtesy G.Kindlmann
Surgical Planning Laboratoryhttp://www.slicer.org-18-
Brigham and Women’s Hospital
Transformation matrices
T: IJKRAS
(X,Y,Z) (I,J,K)
T: XYZRAS
(R,A,S) Courtesy G.Kindlmann
Surgical Planning Laboratoryhttp://www.slicer.org-19-
Brigham and Women’s Hospital
Nrrd Terminology
T: XYZRAS
(X,Y,Z) (I,J,K)
(R,A,S)
T: IJKRAS
Courtesy G.Kindlmann
Surgical Planning Laboratoryhttp://www.slicer.org-20-
Brigham and Women’s Hospital
Nrrd requirements for DWI data
To generate a Nrrd header for DWI data, you’ll
need to know information about data representation:
• DWI Volume characteristics– Data Type – Endianess– Dimensions
• Disk Storage– Axis Ordering
Surgical Planning Laboratoryhttp://www.slicer.org-21-
Brigham and Women’s Hospital
Nrrd requirements for DWI data
To generate a Nrrd header for DWI data, you’ll
need to know the acquisition parameters:
• Coordinate Frames– DWI Image Orientation– Gradient Measurement Frame
Surgical Planning Laboratoryhttp://www.slicer.org-22-
Brigham and Women’s Hospital
Overview
• Part 1: DWI data specificity
• Part 2: Nrrd description
• Part 3: Generating Nrrd Files
• Part 4: Working with DICOM DWI training data
• Part 5: Orientation validation within Slicer
Surgical Planning Laboratoryhttp://www.slicer.org-23-
Brigham and Women’s Hospital
Generating Nrrd Files
• Nrrd files can be generated from the Tk console of Slicer using the “unu” command line tool
• unu is part of set of libraries called “Teem” compiled into Slicer 2.6
http://teem.sourceforge.net/• Slicer includes a Nrrd reader to load DWI volumes in Nrrd
format
Surgical Planning Laboratoryhttp://www.slicer.org-24-
Brigham and Women’s Hospital
Unu syntax
• General Syntax:
unu cmd -i input -o output
• Tips:
“unu” list of unu commands
“unu cmd” help on cmd
Surgical Planning Laboratoryhttp://www.slicer.org-25-
Brigham and Women’s Hospital
Unu syntax: ‘make’ command
• ‘make’ syntax:
unu make -i input -o output
• ‘make’ documentation:
unu make help on make
Surgical Planning Laboratoryhttp://www.slicer.org-26-
Brigham and Women’s Hospital
Running unu on Windows
To run the unu command from the Tk
console, type unu.
On Windows, you do not need to be in the
directory win32/bin/teem-build/bin
the unu commands run from any location.
Surgical Planning Laboratoryhttp://www.slicer.org-27-
Brigham and Women’s Hospital
Running unu on Mac/Linux/Solaris
To run the unu command from the Tk console,
you need to enter the whole path to the /bin
directory
Ex: Mac ../slicer2.6-opt-darwin-ppc-2006-05-18/Lib/darwin-ppc/teem-build/bin
Surgical Planning Laboratoryhttp://www.slicer.org-28-
Brigham and Women’s Hospital
Overview
• Part 1: DWI data specificity
• Part 2: Nrrd description
• Part 3: Generating Nrrd Files
• Part 4: Working with DICOM DWI training data
• Part 5: Orientation validation within Slicer
Surgical Planning Laboratoryhttp://www.slicer.org-29-
Brigham and Women’s Hospital
DICOM DWI Training Data
• 2 Baselines and 12 Gradients
• 504 DICOM images named S4.xxx where xxx is the image number
Surgical Planning Laboratoryhttp://www.slicer.org-30-
Brigham and Women’s Hospital
DWI Training Data
Type the command cd and enter the path to your data in the Tk Console. Type ls to list all the data files.
Surgical Planning Laboratoryhttp://www.slicer.org-31-
Brigham and Women’s Hospital
DWI Training Data
The dataset is composed of 504 images named S4.xxx
Surgical Planning Laboratoryhttp://www.slicer.org-32-
Brigham and Women’s Hospital
unu make -h --input S4.%03d 1 504 1 2 --encoding raw --byteskip -1
Unu command (Windows)Type the unu command with the input, encoding and byteskip fields
Min index
Max index Increment
2D Image Read backwards from end of file
Do not hit Enter
Surgical Planning Laboratoryhttp://www.slicer.org-33-
Brigham and Women’s Hospital
unu make -h --input S4.%03d 1 504 1 2 --encoding raw --byteskip -1
Unu command (Mac/Linux)Type the unu command with the input, encoding and byteskip fields
Min index
Max index Increment
2D Image Read backwards from end of file
slicer2.6-opt-darwin-ppc-2006-05-18/Lib/darwin-
ppc/teem-build/bin
Surgical Planning Laboratoryhttp://www.slicer.org-34-
Brigham and Women’s Hospital
Numbers as file naming convention (*)
• % is a special character to be replaced by the specific file number (cf C/C++ printf command)
• %03d means a 3 digit number with zero “padding”: Padding means there will be zeros instead of spaces at the beginning of the number
Ex: %03d S4.001 for file number 1%03d S4.024 for file number 24
• This is a compact way to refer to the whole image sequence
(*) Background information
unu make -h --input S4.%03d 1 504 1 2 --encoding raw --byteskip -1
Surgical Planning Laboratoryhttp://www.slicer.org-35-
Brigham and Women’s Hospital
Read the DICOM Header
Click on AddVolume
Surgical Planning Laboratoryhttp://www.slicer.org-36-
Brigham and Women’s Hospital
Select the Properties Dicom
The Props panel appears.
Read the DICOM Header
Surgical Planning Laboratoryhttp://www.slicer.org-37-
Brigham and Women’s Hospital
Click on Select DicomVolume and browse to
load the dataset located in
the directory dwi-dicom
The Dicom Props panel appears.
Read the DICOM Header
Surgical Planning Laboratoryhttp://www.slicer.org-38-
Brigham and Women’s Hospital
Slicer displays the list of
Dicom files in the directory.
Click on OK
Read the Dicom Header
Surgical Planning Laboratoryhttp://www.slicer.org-39-
Brigham and Women’s Hospital
Click on Extract Header to display the content of the Dicom Header.
Read the Dicom Header
Surgical Planning Laboratoryhttp://www.slicer.org-40-
Brigham and Women’s Hospital
Slicer displays the content of the Dicom Header.
This information will be used to generate the Nrrd header.
Read the Dicom Header
Surgical Planning Laboratoryhttp://www.slicer.org-41-
Brigham and Women’s Hospital
Extract the values corresponding to the following information:
- Data Type
- Endianess
- Image Dimensions
Extracting the volume characteristics
Surgical Planning Laboratoryhttp://www.slicer.org-42-
Brigham and Women’s Hospital
- Data Type: Short
- Endianess: Little
Extracting the volume characteristics
Surgical Planning Laboratoryhttp://www.slicer.org-43-
Brigham and Women’s Hospital
Unu CommandAdd the fields endian and type to the unu command
--endian little --type short
Surgical Planning Laboratoryhttp://www.slicer.org-44-
Brigham and Women’s Hospital
The dataset was acquired with Nb=2 Baselines and Ng=12 Gradients
Extracting the volume characteristics
Image Dimensions: 256 pixels x 256 pixels
Surgical Planning Laboratoryhttp://www.slicer.org-45-
Brigham and Women’s Hospital
DICOM DWI Training Data
• 2 Baselines and 12 Gradients
• 504 DICOM images named S4.xxx where xxx is the image number
Surgical Planning Laboratoryhttp://www.slicer.org-46-
Brigham and Women’s Hospital
The dataset was acquired with Nb=2 Baselines and Ng=12 Gradients
n=NbxNg = 12 + 2 = 14 intensity values/voxel
NSlices= NdicomImages/n = 504/14 = 36 slices
Extracting the volume characteristics
Image Dimensions: 256 pixels x 256 pixels
Surgical Planning Laboratoryhttp://www.slicer.org-47-
Brigham and Women’s Hospital
Unu Command
--size 256 256 36 14
--centering cell cell cell none
Medical images are
cell-centered samples
Add the fields size and centering to the unu command
Surgical Planning Laboratoryhttp://www.slicer.org-48-
Brigham and Women’s Hospital
Slice Thickness
Extract the slice thickness from the Dicom header
Surgical Planning Laboratoryhttp://www.slicer.org-49-
Brigham and Women’s Hospital
Slice Thickness
slice thickness = 3.00 mm
Surgical Planning Laboratoryhttp://www.slicer.org-50-
Brigham and Women’s Hospital
Slice Thickness
--thickness nan nan 3.0 nan
Add the field thickness to the unu command
Surgical Planning Laboratoryhttp://www.slicer.org-51-
Brigham and Women’s Hospital
Building the transformation matricesWe specifically change orientation from the DICOM default of LeftPosterior-Superior (LPS) to Right-Anterior-Superior (RAS)so that the data can be viewed in Slicer coordinate space
DICOM: LPS SLICER: RAS
Surgical Planning Laboratoryhttp://www.slicer.org-52-
Brigham and Women’s Hospital
Space DirectionsAdd the field space to the unu command
--space right-anterior-superior
Surgical Planning Laboratoryhttp://www.slicer.org-53-
Brigham and Women’s Hospital
Space Directions
Extract the pixel size from the Dicom Header.
Surgical Planning Laboratoryhttp://www.slicer.org-54-
Brigham and Women’s Hospital
Space Directions
Pixel size = 0.9375 mm x 0.9375 mm
The dataset was acquired with Superior-Inferior slice ordering
Surgical Planning Laboratoryhttp://www.slicer.org-55-
Brigham and Women’s Hospital
Space Directions
--directions “(-0.9375,0,0) (0,-0.9375,0) (0,0,-3) none“
Add the fields directions and unit to the unu command
DICOM: LPS SLICER: RAS
Surgical Planning Laboratoryhttp://www.slicer.org-56-
Brigham and Women’s Hospital
Space Origin
Courtesy G.Kindlmann
The space origin is the position of the first pixel in the first image.
This information is contained in the Dicom Header of the first slice.
Surgical Planning Laboratoryhttp://www.slicer.org-57-
Brigham and Women’s Hospital
Space Origin
The space origin information is located in the Dicom header
[0020,0032, Image Position Patient ]
Courtesy G.Kindlmann
Surgical Planning Laboratoryhttp://www.slicer.org-58-
Brigham and Women’s Hospital
Space Origin
Click on Cancel to come back to the Main menu
Create a directory calledFirstSlice and copy the first fileS4.001 of the Dicom-dwidataset
Surgical Planning Laboratoryhttp://www.slicer.org-59-
Brigham and Women’s Hospital
Space Origin
Click Add Volumeselect the tab Props, and the format DICOM
Surgical Planning Laboratoryhttp://www.slicer.org-60-
Brigham and Women’s Hospital
Space Origin
Click on Select DICOM Volume
Select the directory /FirstSlicecontaining the first slice
Surgical Planning Laboratoryhttp://www.slicer.org-61-
Brigham and Women’s Hospital
Space Origin
Click on List Headers to
display the content of the
header of the first image.
Surgical Planning Laboratoryhttp://www.slicer.org-62-
Brigham and Women’s Hospital
Space Origin
Slicer displays the content of
the header of the first image.
Surgical Planning Laboratoryhttp://www.slicer.org-63-
Brigham and Women’s Hospital
Space Origin
Scroll down to display the value of the tag [0020,0032, Image Position Patient ]
Surgical Planning Laboratoryhttp://www.slicer.org-64-
Brigham and Women’s Hospital
Space Origin
[0020,0032, Image Position Patient ] = -125.0, -124.09, 79.30
Surgical Planning Laboratoryhttp://www.slicer.org-65-
Brigham and Women’s Hospital
Space Origin
Click on OK to close the Dicom Header Window
Surgical Planning Laboratoryhttp://www.slicer.org-66-
Brigham and Women’s Hospital
Space Origin
--origin "(+125.0,+124.10,79.30)"
Add the field origin to the unu command
DICOM: LPS SLICER: RAS
Surgical Planning Laboratoryhttp://www.slicer.org-67-
Brigham and Women’s Hospital
Measurement Frame
Surgical Planning Laboratoryhttp://www.slicer.org-68-
Brigham and Women’s Hospital
Measurement Frame
Surgical Planning Laboratoryhttp://www.slicer.org-69-
Brigham and Women’s Hospital
Measurement Frame
--measurementframe “(0,-1,0) (1,0,0) (0,0,-1)"
Add the field measurement frame to the unu command
Surgical Planning Laboratoryhttp://www.slicer.org-70-
Brigham and Women’s Hospital
Axis Ordering
Courtesy G.Kindlmann
Surgical Planning Laboratoryhttp://www.slicer.org-71-
Brigham and Women’s Hospital
Axis Ordering
--kind space space space list
Add the field kinds to the unu command
Axis Ordering: columns, rows, slices, intensity values
Surgical Planning Laboratoryhttp://www.slicer.org-72-
Brigham and Women’s Hospital
Output FileAdd the field output to the unu command
--output myNrrdDWI.nhdr
Surgical Planning Laboratoryhttp://www.slicer.org-73-
Brigham and Women’s Hospital
Output File
Type ls in the Tk Console
The file myNrrdDWI.nhdr is listed in the directory
Surgical Planning Laboratoryhttp://www.slicer.org-74-
Brigham and Women’s Hospital
Acquisition parametersOpen the file MyNrrdDWI.nhdr with a text Editor
Surgical Planning Laboratoryhttp://www.slicer.org-75-
Brigham and Women’s Hospital
Acquisition parametersOpen a web browser at the location
http://www.na-mic.org/Wiki/index.php/Dartmouth-DWI-parameters
Surgical Planning Laboratoryhttp://www.slicer.org-76-
Brigham and Women’s Hospital
Acquisition parametersCopy the acquisition parameters from this wiki page to the end of the file
MyNrrdDWI.nhdr, hit Enter and save the resulting file
Surgical Planning Laboratoryhttp://www.slicer.org-77-
Brigham and Women’s Hospital
Result
Final result of the tutorial: Nrrd header for the DWI training dataset
Surgical Planning Laboratoryhttp://www.slicer.org-78-
Brigham and Women’s Hospital
Overview
• Part 1: DWI data specificity
• Part 2: Nrrd description
• Part 3: Generating Nrrd Files
• Part 4: Working with DICOM DWI training data
• Part 5: Orientation validation within Slicer
Surgical Planning Laboratoryhttp://www.slicer.org-79-
Brigham and Women’s Hospital
Loading the Nrrd Volume
Click on Cancel to come back to the Main Menu
Surgical Planning Laboratoryhttp://www.slicer.org-80-
Brigham and Women’s Hospital
Loading the Nrrd Volume
Click on Add Volume to load the DWI training dataset using the Nrrd header
Surgical Planning Laboratoryhttp://www.slicer.org-81-
Brigham and Women’s Hospital
Loading the Nrrd Volume
Select Nrrd Reader in the Properties field
The Props Panel of the module Volumes appears.
Surgical Planning Laboratoryhttp://www.slicer.org-82-
Brigham and Women’s Hospital
Loading the Nrrd Volume
Click on Apply
Check that the path to the file myNrrdDWI.nhdr is correct. If needed, manually enter it
Browse to load the file myNrrdDWI.nhdr
Surgical Planning Laboratoryhttp://www.slicer.org-83-
Brigham and Women’s Hospital
Loading the Nrrd Volume
Slicer loads the Nrrd DWI dataset
Left-click on Or and change the orientation to Slices
Surgical Planning Laboratoryhttp://www.slicer.org-84-
Brigham and Women’s Hospital
Loading the Nrrd Volume
Change the FOV to 2000
Surgical Planning Laboratoryhttp://www.slicer.org-85-
Brigham and Women’s Hospital
Loading the Nrrd Volume
The sagittal and coronal viewers display the 14 DWI volumes: 2 baselines and 12 gradients
Surgical Planning Laboratoryhttp://www.slicer.org-86-
Brigham and Women’s Hospital
Loading the Nrrd Volume
Display the axial and sagittal slices inside the viewer.
Use the axial slider to observe the baselines and gradient volumes.
Surgical Planning Laboratoryhttp://www.slicer.org-87-
Brigham and Women’s Hospital
Converting the DWI data to tensors
Select the module DTMRI and click on the tab Conv
Select the Input volume myNrrdDWI.nhdr and click on ConvertVolume
Surgical Planning Laboratoryhttp://www.slicer.org-88-
Brigham and Women’s Hospital
Converting the DWI data to tensors
Slicer displays the anatomical views of the Average Gradient volume.
Surgical Planning Laboratoryhttp://www.slicer.org-89-
Brigham and Women’s Hospital
Glyphs
Select the panel Glyphs in the DTMRI module
Select the Active DTMRI volume myNrrdDWI-nhdr_Tensor
Select Glyphs on Slice for the axial (red) view
Set Display Glyphs On
Surgical Planning Laboratoryhttp://www.slicer.org-90-
Brigham and Women’s Hospital
Glyphs
Orientation of the glyphs in the Corpus Callosum
Surgical Planning Laboratoryhttp://www.slicer.org-91-
Brigham and Women’s Hospital
Conclusion
• Standardized description of the information contained in DWI data.
• Rapid, intuitive visual assessment of orientation results within Slicer
• Open-Source: http://teem.sourceforge.net/nrrd/