/**
\page QmitkDiffusionImagingDataImportPage Data formats, import and export

MITK Diffusion supports many standard image formats such as NIFTI, NRRD and DICOM as well as common tractography file formats such as vtk/fib, trk, tck, and tractography DICOM. By including multiple tractography file formats native to other tools (e.g. 3D Slicer, MRtrix, DIPY), MITK Diffusion integrates seamlessly in complex workflows involving other tools. Additional file types such as spherical-harmonic coefficient files and voxel-wise fiber orientation or peak images are compliant with MRtrix.

Data can be loaded using the open file dialog via the menu bar or by simply dragging and dropping the file into the data manager or one of data display windows.

MITK Diffusion uses a left-posterior-superior coordinate system convention. Other toolkits, e.g. MRtrix, use an RAS coordinate system. This can cause flips for example of the complete tractogram or of the voxel-wise peaks or ODFs. MITK Diffusion implements mechanisms to deal with this by automatically catching and converting some cases and by providing the tools to manually correct for it, but it is important to keep this issue in mind and to perform the data processing in a corresponding thorough manner.

\section DWI_format Diffusion-weighted Images

This section describes the different file formats of raw diffusion-weighted images that are supported by MITK Diffusion.
General points:
\li MITK Diffusion internally applies the image rotation matrix to the diffusion-gradient vectors while loading the image. The original gradient directions are retained and used when saving the image again.

\subsection dwi_nrrd NRRD (.nrrd/.dwi)

NRRD (http://teem.sourceforge.net/nrrd/format.html) is the default file format for saving diffusion-weighted images with MITK Diffusion. The gradient and b-value information is directly stored in the file header. The image information is stored as a 3D vector image. Storing the file as .dwi or .nrrd is equivalent, only the file ending is different. Diffusion-weighted images are discerned from other images by the tag "modality:=DWMRI" in the NRRD image header. The gradient information is stored in the NRRD header in the following way:

DWMRI_b-value:=1000.000000

DWMRI_gradient_0000:=0.000000 0.000000 0.000000

DWMRI_gradient_0001:=0.000000 0.000000 1.000000

DWMRI_gradient_0002:=-0.051773 0.252917 0.966102

...

The b-value of the individual gradient directions is encoded via the squared norm of the respective vector. The tag "DWMRI_b-value" defines which b-value corresponds to a vector with norm 1.

In some cases, dMRI NRRD files contain an additional "measurement frame" matrix, which specifies an additional rotation of the gradient vectors. This matrix is automatically applied when loading the file. The original gradient directions are retained and used when saving the image again.

\subsection dwi_nifti NIFTI (.nii/.ni.gz)

Diffusion-weighted images can be saved and loaded as NIFTI files (NIFTI-1 https://nifti.nimh.nih.gov/nifti-1). The gradient vector information is stored in to separate files for b-values (filename.bvals) and gradient vectors (filename.bvecs). When loading a nifti file (.nii or .nii.gz), MITK Diffusion looks for these two additional files (.bval/.bvals and .bvec/.bvecs) and if they are found, MITK will offer to load the image as diffusion-weighted image. In contrast to the NRRD format, all gradient vectors should have a length of 1. The b-values are stored explicietly in the .bval/.bvals file. When loaded into MITK, this information is again encoded into the gradient vectors, as it is done in the NRRD file format.

\subsection dwi_dicom DICOM

MITK is capable of importing diffusion-weighted DICOM images from GE, Siemens and Philips. Writing images is DICOM format is NOT supported! Mosaic images can be directly converted to regular images during import. To load a dMRI DICOM, simply drag and drop any file of the series into the application.

\section special_format Special Image Types

\subsection DTI_format Diffusion Tensor Images (.dti)

The default format for diffusion tensor images in MITK Diffusion is a 3D NRRD file with a "3D-symmetric-matrix" pixel type. A tensor is encoded as 6 float values. The file ending for diffusion tensor files is .dti.
MITK Diffusion is also able to read NIFTI DTI files (6 or 9 component format), which are for example generated by the Camino multi tensor reconstruction. To be recognized as DTI files, the .nii or .nii.gz files have to be renamed to .dti.

\subsection ODF_format ODF Images (.odf, .qbi (deprecated) )

MITK stores ODFs as 252 float values spherically sampled from the continuous ODF. The sampling directions are generate by a 5-fold subdivisions of an icosahedron. ODF images are stored in NRRD file format with the ending .odf. The image information is stored as a 3D vector image with a vector length of 252.

The specific ODF sampling directions can be found <a href="https://phabricator.mitk.org/source/mitk/browse/master/Modules/DiffusionImaging/DiffusionCore/include/Algorithms/Reconstruction/itkPointShell.txx;8cdb084b2eccff7f5caa30ba5a88bf43ccc9ec6f$457">here</a>.

\subsection sh_format Spherical Harmonics
Many applications in dMRI are using spherical harmonics to store spherical functions such as ODFs. MITK Diffusion stores these files as 3D vector images (NRRD format), where the vector components represent the SH coefficients. While this format is different from e.g. the MRtrix SH file format, MITK Diffusion can convert from MRtrix SH files to MITK Diffusion SH files. For historical reasons, the conversion tool is located in the \ref org_mitk_views_odfmaximaextraction view. Simply load the MRtrix SH image, select it in the data manager, select the "MRtrix" spherical harmonics convention and click "Start SH Coefficient Import".

\subsection peak_format Peak Images (.nii, .nii.gz, .nrrd)

MITK Diffusion stores peak images, resulting for example from an ODF maxima extraction, as 4D float images. The peak vector components are stored in the 4th dimension, therefore dimension 4 always contains a multiple of 3 entries. This format is the same as the format used by MRtrix.

\section Tract_format Tractography Formats

MITK Diffusion supports multiple formats for tractography files that are commonly used in the dMRI community. As in all other toolkits, the fiber point coordinates are stored as physical/world coordinates without any additional transformation.

\subsection tract_vtk VTK (.vtk/.fib)

The default format for tractograms is VTK (vtkPolyData) with the file endings .fib or .vtk. The advantage of the VTK format is that it can store additional information such as fiber weights and fiber colors. By default, both are saved with the actual tract information.

\subsection tract_trk TrackVis (.trk)

TRK is the tractography file format used by TrackVis and DIPY. See http://www.trackvis.org/docs/?subsect=fileformat for a detailed description of a format.

\subsection tract_tck MRtrix (.tck)

MITK Diffusion is able to read the tck file format native to MRtrix. Writing this format is currently not supported. By default, MRtrix uses a RAS coordinate convention in contrast to the MITK Diffusion (and also ITK) convention of LPS. To compensate for this, the fiber coordinates are negated in the x and y dimension.

\subsection tract_dicom DICOM

Tractography DICOM files compliant with the supplement 181 of the DICOM standard can be read and written by MITK Diffusion. This format is for example supported by the neuronavigation software of Brainlab.
DICOM tags of the read tractogram can be manually set or modified using the "Properties" view in MITK Diffusion. To do this, enable the "Developer Mode" option in Window>Preferences>Properties>Developer Mode. Then select the fiber bundle in the data manager and select the "Base Data" property list in the corresponding combobox of the "Properties" view.
*/
