Here we present PyDesigner, a Python-based diffusion magnetic resonance imaging (dMRI) processing pipeline capable of correcting for typical dMRI artifacts and producing diffusion tensor imaging (DTI), diffusion kurtosis imaging (DKI), fiber ball imaging (FBI), microstructure modeling (white matter integrity [WMTI] and fiber ball white matter [FBWM]), and tractography outputs.
PyDesigner is a Python-based software package based on the original Diffusion parameter EStImation with Gibbs and NoisE Removal (DESIGNER) pipeline (Dv1) for dMRI preprocessing and tensor estimation. This software is openly provided for non-commercial research and may not be used for clinical care. PyDesigner combines tools from FSL and MRtrix3 to perform denoising, Gibbs ringing correction, eddy current motion correction, brain masking, image smoothing, and Rician bias correction to optimize the estimation of multiple diffusion measures. It can be used across platforms on Windows, Mac, and Linux to accurately derive commonly used metrics from DKI, DTI, WMTI, FBI, and FBWM datasets as well as tractography ODFs and .fib files. It is also file-format agnostic, accepting inputs in the form of .nii, .nii.gz, .mif, and dicom format. User-friendly and easy to install, this software also outputs quality control metrics illustrating signal-to-noise ratio graphs, outlier voxels, and head motion to evaluate data integrity. Additionally, this dMRI processing pipeline supports multiple echo-time dataset processing and features pipeline customization, allowing the user to specify which processes are employed and which outputs are produced to meet a variety of user needs.
Diffusion MRI (dMRI) is widely applied for the noninvasive study of microstructural properties in the brain. While many dMRI methods have been proposed, two commonly used are diffusion tensor imaging (DTI) and diffusional kurtosis imaging (DKI). These techniques are closely related, with DKI being an extension of DTI that includes quantification of diffusional non-Gaussianity1. Both provide a variety of scalar diffusion measures and enable the construction of white matter fiber tractography. An important advantage of DTI and DKI is that they have a solid foundation in diffusion physics so that their validity does not rely on detailed assumptions regarding tissue microstructure2,3. This allows DTI and DKI to be applied throughout the brain and body for participants of any age and disease status.
Because raw diffusion-weighted images (DWIs) are degraded by multiple factors, including signal noise, motion, Gibbs ringing, and eddy current distortion, preprocessing should be employed prior to the calculation of any diffusion quantities4. Preprocessing of DWIs is an active field of research that is now highly developed. However, combining the necessary processing steps into a single pipeline that gives consistent results is challenging because several user-defined settings must be adjusted depending on the details of the dMRI acquisition and because the order in which the preprocessing steps are performed affects the outcome. For this reason, the Diffusion parameter EStImation with Gibbs and NoisE Removal (DESIGNER, GitHub: NYU-DiffusionMRI/DESIGNER) pipeline was initially proposed in 2016 to optimize, standardize, and streamline the preprocessing for DWIs5. DESIGNER Dv1 relies on software tools that are embedded in FSL, MRtrix3, MATLAB, and Python to create a seamless and complete DWI process – one that encompasses image correction through preprocessing and diffusion/kurtosis tensor estimation5. With control flags to toggle preprocessing steps on or off, DWI corrections can be performed selectively. DESIGNER preprocesses in a specific order – (i) Marchenko-Pastur principal component analysis (MP-PCA) denoising6, (ii) Gibbs ringing correction7, (iii) echo-planar imaging (EPI) distortion correction8, eddy current correction9, motion correction10, and outlier replacement11, (iv) B1 bias field correction, (v) brain mask generation, (vi) smoothing, (vii) Rician noise bias correction, and (viii) b0 normalization. Preprocessing in this specific order improves both accuracy and the effective signal-to-noise ratio (SNR)5. It is worth noting that each step of PyDesigner is optional and can be employed or skipped based on user preference. Smoothing, for example, may not be a necessary preprocessing step for some datasets. Though it helps to mitigate filtering errors, it may not be needed for ultra-high-quality datasets. As such, users can choose to employ only the steps needed for their data.
Implementing DESIGNER across platforms is challenging due to differences in operating systems and environment settings. In particular, the fact that DESIGNER Dv1 is primarily written in MATLAB creates significant portability issues arising from complicated configuration requirements needed to enable Python-MATLAB interfacing. Moreover, different combinations of MATLAB, Python, and dependency versions compromise the reproducibility of this pipeline. For this reason, we have developed PyDesigner, which is entirely Python-based. Not only does this dMRI processing pipeline allow for seamless preprocessing, but it also allows the pipeline to be incorporated into a Docker container, which greatly enhances portability and reproducibility. Additionally, by replacing the MATLAB code, PyDesigner avoids all licensing fees and improves accessibility.
This dMRI processing pipeline augments the hands-free approach introduced by DESIGNER, adds several new features, and incorporates tools from FSL and MRtrix3 to perform preprocessing. Standard mathematical Python libraries such as Numpy12, SciPy13, and CVXPY14,15 were used to replace the MATLAB portions of DESIGNER with Python code. This software is openly provided and available on Github16. The goal of this paper is not to validate or compare our software to similar software but rather to give users a step-by-step guide for processing their data with PyDesigner should they choose to do so.
The primary motivation for developing PyDesigner was to implement the key elements of DESIGNER while replacing all MATLAB code with Python, thereby allowing greater portability and accessibility. PyDesigner and DESIGNER Dv1 yield nearly identical outputs29. Nonetheless, there are a few additional options, default settings and minor bug fixes included in PyDesigner. The online PyDesigner documentation16 describes these in detail.
PyDesigner also yields similar results to commonly used Diffusional Kurtosis Estimator (DKE)27 and Diffusion Imaging in Python (DIPY)28 DKI analysis tools29 (see Figure 6 and Figure 7) but the maps generated based on DESIGNER-preprocessed dMRI are considered to be more accurate due to their fitting algorithm as demonstrated by Ades-Aron et al.5. See Figure 6 for a comparison of the MD, FA, and MK metric maps from PyDesigner, DESIGNER5, DKE27, and DIPY28. Figure 7 shows the comparison of MD, FA, and MK histograms from each pipeline. Combining constrained tensor fitting, outlier detection, and apparent kurtosis coefficient correction yields a more robust and accurate tensor fitting, as seen in PyDesigner and DESIGNER5.
An advantage of PyDesigner over DESIGNER Dv1 is that it is available via the NeuroDock Docker container30, which greatly enhances portability and simplifies installation. This container runs across all major OS platforms compatible with Docker, including Windows, Mac OS, and various Linux distributions. Based on user feedback, PyDesigner v2.0 will include updates to the PyDesigner Docker Container. The improvements introduced by the new version of PyDesigner and the introduction of a multi-stage Dockerfile will resolve all existing issues that users are facing. If users have issues with installation, we recommend submitting questions to the PyDesigner discussion page16. Docker's container technology also enables straightforward deployment to high-performance clusters (HPCs) for batch processing DWIs quickly on Docker-compatible local clusters.
PyDesigner also includes microstructural modeling calculations that go beyond DKI, including WMTI3, FBI, and FBWM. For WMTI, a standard DKI dataset is adequate, and the associated microstructural parameters are calculated by default. However, it should be emphasized that the validity of WMTI is restricted to white matter regions with high FA (i.e., FA ≥ 0.4). Some WMTI metrics have limited accuracy due to the assumption of parallel alignment of axons in any given voxel31. FBI32,33,34 is a distinct dMRI method applicable throughout the cerebral white matter, which requires a high b-value (i.e., b ≥ 4000 s/mm2) and dMRI data sampled with a minimum of 64 diffusion encoding directions (along with data for b = 0). The main outputs of FBI are the fiber orientation density function (fODF) for each white matter voxel, which can be used for white matter tractography and serves as an input for FBWM, as well as the intra-axonal fractional anisotropy (FAA). FBWM utilizes the dMRI data from both DKI and FBI to estimate the same parameters as WMTI but with improved accuracy, and it can be applied throughout the white matter regardless of the FA value. Thus, if this additional data is available, then FBWM estimates are preferred over those from WMTI35. As with FBI, FBWM has only been validated in adult cerebral white matter.
In addition to the rotational invariants provided by PyDesigner (RAS orientation), .fib files specific to DSIstudio (LPS orientation) are produced separately for DTI, DKI, and FBI. The .fib files contain ODF directional information for generating tractography profiles for each method. The resulting tractography profiles can be used to generate connectivity matrices at subject and group levels. The DKI and FBI .fib files contain multi-directional information relaying crossing fiber information which is not available with DTI tractography. Moreover, within each .fib file, the various rotational invariants of each method have been included, which can be used in various combinations as criteria for seeding, performing, and stopping the tractography. Further details on DSIstudio can be found on their website36.
Another notable feature of PyDesigner is multi-file input, which allows it to handle various file inputs – NifTi (.nii), compressed NifTi (.nii.gz), DICOM (.dcm), and MRtrix file format (.mif). PyDesigner can automatically identify acquisition information from header metadata regardless of input format and perform corrections accordingly, thereby supporting a hands-off approach. Regardless of differences in protocols, the same command (see above) can be used to process a wide variety of DWIs. This software thus saves time and effort by minimizing manual preprocessing steps and commands. In a recently released update (v1.0-RC10), this has been enhanced by introducing compatibility for multiple echo-time (multi-TE) datasets. This allows PyDesigner to run image preprocessing steps, which are largely independent of TE, on a multi-TE DWI to yield an image with minimal noise and artifacts. TE-dependent tensor calculations are then performed on each TE separately to produce diffusion or kurtosis metrics.
We note that PyDesigner v1.0 does not represent an endpoint in the design of image preprocessing pipelines. The development and validation of image processing tools is an active area of research. In particular, during the preparation of this manuscript, new developments in image denoising and Gibbs ringing removal were proposed, resulting in the release of a revised Designer pipeline, Designer Dv237, that includes improved denoising and correction of Gibbs artifacts for dMRI acquired with Partial Fourier acquisitions35, and is available on the DESIGNER Github38. Likewise, BIDS39 organizational compliance is an important facet of any MRI analysis pipeline. The BIDS format allows for more efficient data sharing and pipeline implementation by establishing a specific set structure for all MRI datatypes. Although PyDesigner is not currently BIDS-compliant, an upcoming version of PyDesigner will include BIDS-compliant outputs. Additionally, PyDesigner was originally written using Python version 3.7. At the time of this publication, Python 3.7 is now considered outdated. However, the information contained in this manuscript is independent of the Python version. That is, the procedures described herein that are important preprocessing functions (e.g., denoising, Gibbs ringing correction, etc.) will follow the same operational and conceptual workflow irrespective of changes in installation procedures. Importantly, as with all Python-based software, future PyDesigner versions will update to a new version of Python. We strive to validate and integrate such developments further over time.
For the most up-to-date version of PyDesigner, including any new documentation relevant to Python version updates, readers are encouraged to consult the website prior to beginning a new analysis and engage in the discussion forum where questions regarding PyDesigner can be submitted16. The Docker implementation for portability is called NeuroDock30, which contains PyDesigner and its dependencies to enable processing across a wide array of platforms.
The authors have nothing to disclose.
We are grateful for the helpful discussions with Olivia Horn, Daniel Lench, and Graham Warner.
Research reported in this publication was supported, in part, by National Institutes of Health grants R01AG054159, R01AG057602, R01AG055132, R01DC014021, R01NS110347, R21DA050085, F31NS108623, P20GM109040, P50DC000422, T32GM008716, and T32DC014435. The content is solely the responsibility of the authors and does not necessarily represent the official views of the National Institutes of Health. Additional funding was provided by the Litwin Foundation.
Python version 3.7 or above | Python Software Foundation | https://www.python.org/ | |
FMRIB Software Library (FSL) verison 6.0.2 or above | University of Oxford Centre for Integrative Neuroimaging | https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/ | |
MRtrix3 version 3.0_RC3 or above | numerous contributors | https://www.mrtrix.org/ | |
Anaconda | Anaconda | https://anaconda.org/ | |
Computer | Apple | Mac OS 10.14 | Built on Mac OS 10.14; tested on Mac OS 12.4, Mac OS 13, Windows 11 via WSL |
.