Skip to content

scientificcomputing/kg-jebsen-brain-fluid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

MRI-to-FEM Pipelines for FEniCS(x)

This document outlines the workflows used at Simula for converting raw MRI data into finite element meshes suitable for FEniCS/FEniCSx simulations. It covers current software choices, specific user pipelines, dataset locations, and future development needs.

1. Quick Reference: Current Workflows

A summary of who is using what, serving as a point of contact for specific variations of the pipeline.

Contact Meshing Engine Segmentation Source Dataset / Repo Key Notes
Ingvild Ftetwild FreeSurfer / SynthSeg OpenNeuro ds004478 Uses mri2mesh. Feature request: Node index tracking.
Andreas SVMTK FreeSurfer SVMTK Repo Standard SVMTK pipeline.
Henrik Ftetwild NeuroQuant Biophysics Repo Uses a config-file driven approach. Handles NeuroQuant labels (different from FS).
Cecile Ftetwild FreeSurfer / SynthSeg CerebroSpinalFlow Based on Marius Causemann's transport repo.
Timo / Jørgen SVMTK / PyVista FreeSurfer Gonzo SVMTK preferred for surface preprocessing (keeps sulci better than PyVista).

2. Pipeline Stages

Stage 1: Raw Data to Images

Conversion of scanner output (typically DICOM) to research-standard formats (NIfTI).

  • Tools: dcm2niix (Standard), proprietary scanner tools.
  • Target Modalities:
    • T1/T2: Structural anatomy (geometry).
    • Look-Locker: T1 mapping.
    • DTI: Diffusion Tensor Imaging (anisotropy tensors).
    • fMRI/BOLD: Functional activation maps.
    • FLAIR: Fluid-attenuated inversion recovery.

Stage 2: Registration

Aligning different image modalities (e.g., registering DTI to the T1 structural scan) or registering subjects to a common atlas (MNI).

  • Greedy: Fast, effective for standard rigid/affine registration.
  • ANTs: Gold standard for non-linear warping and complex registration.
  • FSL FLIRT: Robust linear registration.

Stage 3: Segmentation

Classifying voxels into tissue types (White Matter, Gray Matter, CSF).

A. FreeSurfer (Standard)

  • Command: recon-all
  • Pros: Industry standard, highly detailed cortical surfaces, separates hemispheres.
  • Cons: Slow (hours), requires high-quality T1.
  • Output: aseg.mgz, lh.pial, rh.white.

B. Deep Learning (SynthSeg)

  • Command: mri_synthseg and recon-all-clinical
  • Pros: Fast (minutes), robust to domain shifts and lower resolution scans.
  • Cons: Surfaces may lack the topological guarantees of FreeSurfer.
  • Note: Also part of FreeSurfer.

Other alternatives we migth want to consider

Stage 4: Surface Extraction

Converting voxel labels into triangular surface meshes (STL/PLY).

  • SVMTK:
    • Works well with output from Freesurfer. Provide fixes for issues introduced by Freesurfer
  • FreeSurfer:
    • Native extraction via mri_tessellate or mri_mc.
  • PyVista:
    • Uses VTK marching cubes. Good for visualization, but requires careful smoothing to avoid non-manifold artifacts in complex brain geometry.

Resources

Stage 5: Meshing (Surface $\to$ Volume)

Creating the tetrahedral mesh for FEniCS / FEniCSx.

1. Wildmeshing (Ftetwild)

2. SVMTK (Surface Volume Meshing Toolkit)

  • Implementation: GitHub Link
  • Pros:
    • Wraps CGAL.
    • Specifically designed for biomedical domains.
    • Excellent utilities for surface repair and subdomain marking.
  • Cons:
    • Only maintained by Lars Magnus Valnes
    • Tricky to install (conda is the best alternative)
  • Examples:

Stage 6: Data Mapping (FEniCSx)

Mapping physiological data from NIfTI images to the generated mesh.

  • Workflow:
    1. Load NIfTI (via nibabel).
    2. Align coordinate systems (RAS vs LPS).
    3. Create FEniCS FunctionSpace (e.g., DG0 for voxels, CG1 for continuous fields).
    4. Probe/Interpolate values.
  • Applications:
    • Tissue properties (conductivity, elasticity).
    • DTI-based diffusion tensors.
    • Concentration maps.
  • Examples:

3. Example Recipe: "The Marius Pipeline"

A hypothetical workflow to go from raw scan to a Stokes + Advection-Diffusion simulation.

  1. Preprocessing:
    • Convert DICOM to NIfTI (dcm2niix).
  2. Segmentation:
    • Run mri_synthseg --i input.nii --o seg.nii (Fast, robust).
  3. Surface Extraction (PyVista):
    • Extract isosurfaces for GM, WM, CSF and perhaps ventricles. Smooth surfaces with PyVista.
    • Save output to .ply files.
  4. Meshing (Ftetwild):
    • Generate tetrahedral mesh from the cleaned surfaces using boolean (union) operations.
    • Mark subdomains (Cell tags) and boundaries (Facet tags).
  5. Simulation (FEniCSx):
    • Import XDMF mesh.
    • Define function spaces.
    • Solve Stokes equations (Fluid flow).
    • Solve Advection-Diffusion (Transport).

4. Demonstration Data

Other data / software at Zenodo


5. Summary of repositories and other resources

About

Meta repository for project planning and resource collection for K.G. Jebsen center for brain fluids

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published