A collection of Python tools for processing 4D flow MRI data, including reconstruction from k-space, velocity calculation, and 3D strain analysis.
- Python 3.x
- NumPy
- SciPy
- Matplotlib
- tqdm
- BART Toolbox (for reconstruction)
For BART toolbox installation, follow instructions at BART website.
The toolkit consists of two main scripts:
Reco_GPU.py- Reconstructs images from k-space data and calculates velocity componentscalc_strain.py- Calculates 3D strain from velocity data
python Reco_GPU.py /path/to/data_dir --venc 20data_dir: Directory containing .cfl/.hdr k-space data files--venc: VENC value in cm/s (default: 20)
This script will:
- Find all .cfl/.hdr pairs in the data directory
- Reconstruct images using BART's parallel imaging tools
- Calculate velocity components (x, y, z) from phase differences
- Create a mask based on magnitude data
- Save all results as .npy files in the same directory
python calc_strain.py --data-path /path/to/data --config config.json--data-path: Directory containing velocity data files--config: Path to JSON configuration file with parameters
--prefix: Prefix of velocity data files (default: "DATA")--mask: Path to mask file (.npy)--roi-mask: Path to region of interest mask file (.npy)--output-eig: Output eigenvalue file (.npy) (default: "Eig_v_output.npy")--output-disp-x: Output displacement x file (.npy)--output-disp-y: Output displacement y file (.npy)--output-disp-z: Output displacement z file (.npy)--output-plot: Output strain plot file (.png)--slice-index: Slice index for 2D analysis--no-display: Do not display plots
Example config.json:
{
"CardiacNumberOfImages": 27,
"InPlaneResolution": [1.5, 1.5],
"SliceThickness": 1.5,
"RepetitionTime": 6.7,
"VelocityDirectionMatrix": [1, 1, 1]
"AffineMatrix":np.eye(4)
}The VelocityDirectionMatrix is a diagonal matrix represented as three values that controls the sign of each velocity component (x, y, z) obtained from the gradient probing sequence. Use 1 for positive, -1 for negative direction.
The affine matrix is extracted from the raw data after conversion to ISMRMRD data with the get_matrix script, if none is provided a identy matrix is used as stand in.
-
Data Reconstruction:
python Reco_GPU.py /path/to/data --venc 25
-
Strain Calculation:
python calc_strain.py --data-path /path/to/data --config settings.json --output-plot strain_results.png
- Velocity components (.npy files)
- Displacement vectors (.npy files, optional)
- Strain eigenvalues (.npy file)
- Strain plot (.png file, optional)
- Nifti of the reconstructed data and velocity maps (.nii file, optional)