◆ FORGE Suite
GitHubMechanical Neuroimaging Lab · Univ. of Delaware
Skip to content

How to Generate a Mesh from MRI Data

Build a hex27 finite element mesh from an MRE acquisition, and write it in the NLI file format the solver reads.

You only need this if you are preparing a mesh as its own step. The .mat entry points (InversionProblem and the sentinel CLI) generate the mesh for you.

1. Read the displacement data

Pick the reader that matches your acquisition:

julia
using Sentinel

# Siemens DICOM (phase images) — directory, frequency (Hz), phase scaling
mre_data = read_mre_siemens("dicom_dir/", 60.0, 1.0)

# WashU .mat format
mre_data = read_mre_washu("washu_data.mat")

# UIUC .mat format
mre_data = read_mre_uiuc("uiuc_data.mat")

All three return an MREData holding the complex displacement arrays, anatomical volume, mask, and voxel spacing.

2. Configure the mesh

julia
config = HexMeshConfig(
    mesh_strategy = 2,     # 1 = voxel, 2 = wavelength, 3 = target resolution
    mu_estimate = 3000.0,  # for the wavelength calculation [Pa]
    rho_estimate = 1000.0, # density [kg/m^3]
    nodes_per_wavelength = 8.0,
    buffer_size = 2,       # boundary padding elements
    spline_bc_type = :natural
)

Choose mesh_strategy by what you want to control:

StrategyElement size is set byUse when
1one node per voxelyou want to preserve the MRI resolution exactly
2the shear wavelengthyou want elements sized to resolve the wave (recommended)
3a resolution you specify, in mmyou need a specific element size

Strategy 2 needs mu_estimate and rho_estimate to compute the wavelength; a rough estimate is enough, since it only sets the element size.

See HexMeshConfig for every field.

3. Generate and write the mesh

julia
result = generate_hex_mesh(mre_data, config)

# NLI-format files: .nod, .elm, .dsp, .bnd
write_hex_mesh_files(result, "output/mesh")

The HexMeshResult carries the Ferrite grid, the full hex27 connectivity, the interpolated displacement data, the boundary nodes, and the metadata.

4. Check the mesh before you invert

Write a VTK file and open it in ParaView to confirm the mesh covers the anatomy and the displacement field looks sensible:

julia
export_vtk("output/mesh_preview", result;
           write_disp = true, write_anatomical = true, write_region = true)

A mesh that is wrong here — wrong extent, holes in the mask, a displacement field that does not look like a wave — will not be rescued by the inversion.

Next