.. include:: links.rst .. _preprocessing: ############# Preprocessing ############# ******************* Building a pipeline ******************* *QSIPrep* builds a pipeline based on your BIDS inputs. In general the pipeline will incorporate all the data it knows how to handle (i.e. fieldmaps, dMRI and anatomical data) automatically. There may be cases where you want to change the default behavior, particularly in regard to 1. :ref:`merging` 2. :ref:`merge_denoise` 3. Head motion correction, either a. :ref:`fsl_wf` b. :ref:`dwi_hmc` 4. :ref:`dwi_only` .. _merging: Merging multiple scans from a session ====================================== For q-space imaging sequences it is common to have multiple separate scans to acquire the entire sampling scheme. These scans get aligned and merged into a single DWI series before reconstruction. It is also common to collect a DWI scan (or scans) in the reverse phase encoding direction to use for susceptibility distortion correction (SDC). .. admonition:: Encoding scan merging intent with BIDS metadata The most appropriate way to explicitly specify which DWIs should be merged is to use the `"MultipartID" metadata field `_. This field is a unique string (per participant) that identifies a set of DWIs that should be considered as part of the same acquisition. If a DWI scan has the same MultipartID as another DWI scan, it will be merged with the other DWI scan. This can be specified across phase encoding directions (PEDs), in which case the DWIs will be merged across PEDs. If you do not specify a ``MultipartID``, *QSIPrep* will group all DWIs within each session. This creates a number of possible scenarios for preprocessing your DWIs. These scenarios can be controlled by the ``--separate-all-dwis`` argument. If your study has multiple sessions, DWI scans will *never* be combined across sessions. Merging only occurs within a session. If ``--separate-all-dwis`` is present in the commandline call, each dwi scan in the ``dwi`` directories will be processed independently. You will have one preprocessed output per each DWI file in your input. Otherwise (default) the DWI scans will be merged (i.e. their images will be concatenated). The merging affects the pipeline at different stages. If all DWIs in a session are in the same PE direction, they will be merged into a single series. If there are two PE directions detected in the DWI scans and ``'fieldmaps'`` is not in ``ignore``, images are combined according to their PE direction, and their b0 reference images are used to perform SDC. Further complicating this is the FSL workflow, which combines distortion correction with eddy/motion correction and will merge scans with different PE directions. If you have some scans you want to combine and others you want to preprocess separately, you can call *QSIPrep* more than once with BIDS filters to process the different scans. .. _bids_filters: Using BIDS filters ================== BIDS filters allow users to filter the set of images available to *QSIPrep* at run time. BIDS filters should be stored in a json file and passed to *QSIPrep* with the ``--bids-filter-file`` option. Filters modify "queries", which are used to find data for each data type. NOTE: this is illustrating how modalities are queried in general, and is not the format of the file you will send to ``--bids-filter-file``. The queries in *QSIPrep* are:: { "fmap": {"datatype": "fmap"}, "t2w": {"datatype": "anat", "suffix": "T2w"}, "t1w": {"datatype": "anat", "suffix": "T1w"}, "roi": {"datatype": "anat", "suffix": "roi"}, "dwi": {"datatype": "dwi", "suffix": "dwi"} } Each query has several "entities", which can be modified by filters. The list of supported entities is `here `__. To filter data, modify the queries by changing one or more of the supported entities in the BIDS filter file. The general format of the filter file is:: { "query": { "entity": "value" } } The entities specified in the filter file are added to the queries, so you only need to include entities you want to use for filtering. For example, this could be the contents of a valid BIDS filter file:: { "t1w": { "session": "MR1" }, "dwi": { "session": "MR1", "run": "1" } } this modifies the "t1w" and "dwi" queries, and filters both T1w and DWI scans to select session "MR1". It also filters on the run number for DWI scans only. Multiple runs can be selected by passing arrays. For example:: { "dwi": { "run": [2,3] } } filters the "dwi" query for runs 2 and 3. You can enable regular expressions for more detailed filtering, for example:: { "t1w": { "acquisition": "(?i)mprage", "regex_search": "true" }, } will do a case-insensitive match of "mprage" within the "t1w" query. .. _merge_denoise: Denoising and Merging Images ============================ The user can decide whether to do certain preprocessing steps and, if so, whether they are performed *before* or *after* the DWI series are concatenated. Specifically, image denoising (using ``dwidenoise`` or ``patch2self``) can be disabled with ``--denoise-method none``. Gibbs unringing (using ``mrdegibbs``) is disabled by default but can be enabled with ``--unringing-method mrdegibbs``. B1 bias field correction is applied by default (using ``dwibiascorrect``) and can be disabled with the ``--dwi-no-biascorr`` option. The intensity of b=0 images is harmonized across scans (i.e. scaled to an average value) by default, but this can be turned off using ``--dwi-no-b0-harmonization``. .. tip:: If prescan normalization is enabled, we recommend using ``--b1-biascorrect-stage none``. This will skip B1 bias field correction, which may introduce artifacts on normalized data. Together, denoising (MP-PCA or patch2self), Gibbs unringing B1 bias field correction and b=0 intensity normalization are referred to as *denoising* in *QSIPrep*. Each of these image processing operations has assumptions about its inputs and changes the distribution of noise in its outputs. Although the inclusion of each operation can be decided by the user, the order in which they are applied relative to one another is fixed. MP-PCA or patch2self are applied directly to the BIDS inputs, which should be uninterpolated and as "raw" as possible. Although Gibbs unringing should be performed on "raw" data, it is recommended in the MRtrix3 documentation to apply MP-PCA before Gibbs unringing. B1 bias field correction and b=0 intensity harmonization do not have as specific requirements about their inputs so are run last. The last, and potentially very important decision, is whether the denoising operations are applied to each input DWI series individually or whether the denoising operations are applied to the concatenated input DWI files. At present, there is little data to guide this choice. The more volumes available, the more data MP-PCA/patch2self have to work with. However, if there if the head is in a vastly different location in different scans, denoising might be impacted in unpredictable ways. Consider MP-PCA. If a voxel contains CSF in one DWI series and the subject repositions their head between scans so that the voxel contains corpus callosum in the next DWI series, the non-noise signal will be very different in the two series. Similarly, if the head is repositioned different areas will be closer to the head coil and therefore be inconsistently affected by B1 bias field. Similar problems can also occur *within* a DWI series due to subject head motion, but these methods have been shown to work well even in the presence of within-scan head movement. If the head position changes across scans is of a similar magnitude to that of within-scan head motion, it is likely fine to use the ``--denoise-after-combining`` option. To gauge how much between-scan motion occurred, users can inspect the :ref:`qc_data` to see whether Framewise Displacement is large where a new series begins. By default, the scans in the same warped space are individually denoised before they are concatenated. When warped groups are concatenated an additional b=0 image intensity normalization is performed. Preprocessing HCP-style ======================= *QSIPrep* can be configured to produce a very similar pipeline to the HCP dMRI pipelines. HCP and HCP-Lifespan scans acquire complete multi-shell sequences in opposing phase encoding directions, making them a special case where :ref:`sdc_pepolar` are used and the corrected images from both PE directions are averaged at the end. To produce output from *QSIPrep* that is directly comparable to the HCP dMRI pipeline you will want to include:: --distortion-group-merge average \ --combine-all-dwis \ If you want to disable the image pair averaging and get a result with twice as many images, you can substitute ``average`` with ``concat``. .. _outputs: ******************** Outputs of *QSIPrep* ******************** *QSIPrep* generates three broad classes of outcomes: 1. **Visual QA (quality assessment) reports**: one :abbr:`HTML (hypertext markup language)` per subject, depicting images that provide a sanity check for each step of the pipeline. 2. **Pre-processed imaging data** such as anatomical segmentations, realigned and resampled diffusion weighted images and the corresponding corrected gradient files in FSL and MRTrix format. 3. **Additional data for subsequent analysis**, for instance the transformations between different spaces or the estimated head motion and model fit quality calculated during model-based head motion correction. 4. **Quantitative QA**: A single-line csv file per subject summarizing subject motion, coregistration quality and image quality. Visual Reports ============== *QSIPrep* outputs summary reports, written to ``/qsiprep/sub-.html``. These reports provide a quick way to make visual inspection of the results easy. One useful graphic is the animation of the q-space sampling scheme before and after the pipeline. Here is a sampling scheme from a DSI scan: .. figure:: _static/sampling_scheme.gif :scale: 75% A Q5 DSI sampling scheme before (left) and after (right) preprocessing. This is useful to confirm that the gradients have indeed been rotated and that head motion correction has not disrupted the scheme extensively. Preprocessed data (*QSIPrep derivatives*) ========================================= There are additional files, called "Derivatives", written to ``/qsiprep/sub-/``. Derivatives related to anatomical files are nearly identical to those produced by ``fMRIprep`` and can be found in the ``anat`` subfolder. One major difference is that the anatomical derivatives are in LPS+ orientation and are realigned to the AC-PC, while ``fMRIprep``'s are in RAS+ orientation and retain the original anatomical images' orientation :: sub-