mri-reconstruction
Actionable MRI image reconstruction — turn raw k-space into an image, and actually run it. Use this WHENEVER the user wants to reconstruct MR data or says things like "reconstruct this k-space", "run BART on this", "get an image from this .cfl / .h5 / twix file", or asks about pa
Install
npx skills add https://github.com/KeWang0622/mri-research-skill/tree/main/skills/mri-reconstruction
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install kewang0622-mri-research-skill@llmmart
git clone https://github.com/KeWang0622/mri-research-skill.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole kewang0622/mri-research-skill collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
MRI Reconstruction (actionable)
You are a reconstruction engineer: given k-space, produce an image — and run the pipeline, don't just talk about it. Default to BART (battle-tested, CLI, scriptable); use SigPy when the user is in Python. Confirm the data before running, then execute and inspect.
Papers and textbooks
See the annotated reading list for primary papers, textbooks, publication details, direct source links and what each source supports. Use the repo-wide reference index to navigate across skills. When using a method, cite its specific source; distinguish paper evidence from software instructions and current venue/safety requirements.
Project research memory
For project experiments, read .mri-research/INDEX.md when present and retrieve
only relevant preferences, environment notes and evidence-linked lessons. After
meaningful runs or corrections, record outcomes, failures, limitations and next
steps; revise scoped lessons without erasing history. Keep user preferences
separate from scientific findings. Use the project memory workflow
to initialize the folder or connect project CLAUDE.md / AGENTS.md. If the hub
is absent, retrieve the reference from the official skill repository.
Tool setup before execution
For any application this skill uses, check for a compatible installation and
follow the official upstream's setup instructions. Within the authorized task,
install missing dependencies yourself in an isolated environment, run a small
upstream example, then execute the user's workflow. Do not leave routine setup
to the user or replace a missing tool with a homemade numerical implementation.
Use established simulators/solvers; write only necessary configuration and glue.
If blocked, report the actual obstacle and an established alternative.
Read the tool setup guide when installing,
repairing, or choosing an execution environment. If the hub is not installed,
retrieve that reference from the official KeWang0622/mri-research-skill repository.
Workflow
0. Identify the k-space format (ask or inspect). BART works in its own
.cfl/.hdr, so other formats need a conversion step:
- BART
.cfl+.hdr— native; dims must be[X Y Z COILS ...](coils on dim 3). Ready to use. - Siemens twix
.dat—bart twixread -A meas.dat kspwrites a.cfl(-Aauto-guesses the dimensions; without it you must supply them explicitly via-x/-y/-z/-c/-s/-n, and a flagless call will not work). Then confirm withbart show -m ksp. Alternative: read in Python withtwixtools/pymapVBVDand write a.cfl. - NumPy array — write a
.cflwith BART's Python helper:PYTHONPATH=$TOOLBOX_PATH/python python -c "import cfl; cfl.writecfl(name, arr)"(cfl.pyships in BART'spython/directory — it is not on PyPI, and the unrelatedbartpypackage on PyPI is a decision-tree library, not this). Make sure coils land on dim 3. - ISMRMRD
.h5— BART has anismrmrdtool, but it is a build-time option: the Makefile defaults toISMRMRD=0, so a stock build has nobart ismrmrdcommand. Check withbart ismrmrd -h; if it's missing, either rebuild BART withISMRMRD=1(needs the ISMRMRD C++ library) or read the file with the Pythonismrmrdpackage andcfl.writecfl. Vendor raw → ISMRMRD first viasiemens_to_ismrmrd/ge_to_ismrmrd/philips_to_ismrmrd.
1. Estimate coil sensitivities (ESPIRiT):
bart ecalib -m1 -r 24 kspace sens
-m1 matters: ecalib computes two ESPIRiT map sets by default, and pics
then returns a soft-SENSE result with a size-2 MAPS dimension instead of a single
image — a silent wrong answer. -r caps the auto-extracted calibration region
(24³ is already the default; lower it if your ACS is smaller).
2. Reconstruct:
# Fully sampled: inverse FFT + coil combine
bart fft -iu 7 kspace img_coils && bart rss 8 img_coils img
# Undersampled — parallel imaging + compressed sensing (the workhorse):
bart pics -l1 -r 0.01 kspace sens img # l1-wavelet regularized
- Non-Cartesian (radial/spiral/cones/rosette): you also need the trajectory.
Use
bart pics -t traj kspace sens img. For calibration, grid with the inverse NUFFT (bart nufft -i), not the adjoint (-a) — the adjoint leaves the sampling density in the data and biases the ESPIRiT maps. Get the trajectory from the sequence/ISMRMRD, orbart trajfor nominal. - EPI is Cartesian. Its zig-zag traversal still samples a Cartesian grid, so do not reach for a trajectory/NUFFT. EPI needs ramp-sampling regridding and Nyquist-ghost / phase correction first, then the Cartesian path above; geometric distortion is corrected downstream (topup/FUGUE).
3. Inspect: check image dimensions, scaling, and orientation; look for
residual aliasing (raise -r), over-smoothing (lower -r), or coil-combination
errors.
Runnable helper
scripts/bart_recon.sh <kspace_cfl> <output_cfl> [l1_reg] [traj_cfl] runs an
ESPIRiT → PI+CS pipeline on a BART .cfl k-space file. It assumes Cartesian
data with coils on dim 3 and a fully-sampled ACS (calibration region); pass a
trajectory .cfl as the 4th argument for genuinely non-Cartesian sampling
(radial/spiral/cones/rosette — not EPI, which is Cartesian). It warns about these
assumptions but can't fully verify them — check the header and adapt the
regularization / calibration size to the data.
SigPy (Python) alternative
import sigpy as sp, sigpy.mri as mr
maps = mr.app.EspiritCalib(ksp).run() # coil maps
img = mr.app.L1WaveletRecon(ksp, maps, lamda=0.01).run() # PI + CS
# non-Cartesian: build a NUFFT from coords, use mr.app.SenseRecon
Guardrails
- Confirm the acceleration factor and sampling (Cartesian vs non-Cartesian) before choosing a method — the wrong forward model gives garbage.
- If BART isn't installed: https://codeberg.org/mrirecon/bart (source, active)
with docs at https://mrirecon.codeberg.page/ — install and validate it when needed. If blocked, explain the
limitation before switching to SigPy. Note the
github.com/mrirecon/bartmirror is archived as of 2026. - Report the SNR cost, not just the image. Acceleration R costs SNR by
g·√R; quote a g-factor (or a pseudo-replica SNR estimate for GRAPPA/ESPIRiT/ nonlinear recon) rather than implying R is free. - Stay in lane: anything trained — unrolled networks, VarNet/MoDL, SSDU,
diffusion priors, fastMRI baselines — belongs to the
deep-learning-reconskill. Designing the acquisition or the trajectory belongs topulse-sequence-design; this skill consumes a trajectory, it doesn't design one. - For method theory and citations, see the hub: https://github.com/KeWang0622/mri-research-skill/blob/main/skills/mri-research/references/recon-methods.md and tool details at https://github.com/KeWang0622/mri-research-skill/blob/main/skills/mri-research/references/tools.md
Files (mri-research-skill)
-
references
-
reading-list.md 2.3 KB
# Papers and textbooks — mri-reconstruction [Skill instructions](../SKILL.md) · [All skill reading lists](../../../REFERENCES.md) A starter reading list, organized by the decision it supports. DOI links lead to publisher records; full text may require library access. Only links explicitly marked as public manuscripts promise that access route. Topic pointers below are reading guidance, not invented chapter or page numbers. ## Parallel imaging and calibration Uecker M, et al. **ESPIRiT—an eigenvalue approach to autocalibrating parallel MRI: Where SENSE meets GRAPPA.** Magnetic Resonance in Medicine, 2014;71:990–1001. [DOI](https://doi.org/10.1002/mrm.24751). **Use it for:** Basis for calibration-derived sensitivity maps and ESPIRiT reconstruction; read before interpreting map sets. ## Compressed sensing Lustig M, Donoho D, Pauly JM. **Sparse MRI: The application of compressed sensing for rapid MR imaging.** Magnetic Resonance in Medicine, 2007;58:1182–1195. [DOI](https://doi.org/10.1002/mrm.21391). **Use it for:** Sampling incoherence, sparsity and nonlinear reconstruction; explains why regularization changes the result. ## Coil combination Roemer PB, Edelstein WA, Hayes CE, Souza SP, Mueller OM. **The NMR phased array.** Magnetic Resonance in Medicine, 1990;16:192–225. [DOI](https://doi.org/10.1002/mrm.1910160203). **Use it for:** Receive-array sensitivity and noise correlations underlying coil combination. ## Background textbook Brown RW, Cheng Y-CN, Haacke EM, Thompson MR, Venkatesan R. **Magnetic Resonance Imaging: Physical Principles and Sequence Design.** 2nd ed. Wiley, 2014. [Publisher / DOI](https://doi.org/10.1002/9781118633953). **Use it for:** Fourier encoding, sampling and image formation before choosing an inverse model. ## Practical references and software [Extended method bibliography](../../mri-research/references/recon-methods.md) · [Tool documentation](../../mri-research/references/tools.md) Software documentation explains installation and APIs; it does not replace the method paper. The curated reading list is not a source for every statement in the skill: cite the specific primary method, current documentation or standard used when answering a research question. If a needed claim is unsupported, find its source or label the uncertainty.
-
-
scripts
-
bart_recon.sh 4.4 KB
#!/usr/bin/env bash # # Parallel-imaging + compressed-sensing MRI reconstruction with BART. # # Usage: # bart_recon.sh <kspace_cfl> <output_cfl> [l1_reg] [traj_cfl] # # Assumptions — VERIFY these before trusting the output; the script warns but # cannot fully check them: # * <kspace_cfl> is a BART .cfl/.hdr file in BART's dimension order, i.e. # coils on dimension 3: [X Y Z COILS ...]. A .cfl written with a # different axis order (e.g. from a NumPy array) will reconstruct to garbage. # * ESPIRiT needs a fully-sampled calibration region (ACS) near the center of # k-space (or fully-sampled data). Prospectively uniform undersampling with # NO ACS gives wrong coil maps — and no error. # * With no trajectory (4th arg) the data is treated as CARTESIAN. That is the # right path for Cartesian GRE/TSE *and for EPI*: EPI traverses k-space in a # zig-zag but its samples lie on a Cartesian grid, so it needs ramp-sampling # regridding and Nyquist-ghost / phase correction UPSTREAM of this script, # not a NUFFT. Pass a trajectory .cfl only for genuinely non-Cartesian # sampling: radial, spiral, cones, rosette, PROPELLER. This script refuses # to guess. # # Requires BART on PATH. BART's active home moved to Codeberg in 2026: # https://codeberg.org/mrirecon/bart (docs: https://mrirecon.codeberg.page/) # The github.com/mrirecon/bart repository is archived and no longer updated. set -euo pipefail KSP="${1:?usage: bart_recon.sh <kspace_cfl> <output_cfl> [l1_reg] [traj_cfl]}" OUT="${2:?usage: bart_recon.sh <kspace_cfl> <output_cfl> [l1_reg] [traj_cfl]}" REG="${3:-0.01}" # L1-wavelet regularization strength TRAJ="${4:-}" # optional BART trajectory .cfl (required for non-Cartesian) command -v bart >/dev/null 2>&1 || { echo "ERROR: BART not found on PATH. Install: https://codeberg.org/mrirecon/bart" >&2; exit 1; } [ -f "${KSP}.cfl" ] && [ -f "${KSP}.hdr" ] || { echo "ERROR: need BART files ${KSP}.cfl and ${KSP}.hdr. Convert vendor/ISMRMRD" >&2 echo " raw to .cfl first (see SKILL.md)." >&2; exit 1; } # Refuse to clobber existing intermediates/outputs the user may care about. for f in "$OUT" "${OUT}_sens"; do if [ -f "${f}.cfl" ]; then echo "ERROR: ${f}.cfl already exists — refusing to overwrite. Choose another" >&2 echo " output name or remove it first." >&2; exit 1 fi done # Intermediates are scratch; clean them up on exit so a rerun is reproducible. TMPBASE="$(mktemp -u "${TMPDIR:-/tmp}/bart_recon_XXXXXX")" cleanup() { rm -f "${TMPBASE}"*.cfl "${TMPBASE}"*.hdr; } trap cleanup EXIT echo ">> k-space dimensions (expect coils on dim 3: X Y Z COILS ...):" bart show -m "$KSP" echo ">> REMINDER: ESPIRiT assumes a fully-sampled calibration region (ACS) near" echo " k-space center. If undersampling removed the ACS, coil maps are wrong." # -m1 is essential: `bart ecalib` computes TWO ESPIRiT map sets by default, which # makes `pics` emit a soft-SENSE result with a size-2 MAPS dimension rather than # a single image. -r caps the auto-extracted calibration region (24^3 is BART's # default; lower it if your ACS is smaller than that). if [ -n "$TRAJ" ]; then [ -f "${TRAJ}.cfl" ] && [ -f "${TRAJ}.hdr" ] || { echo "ERROR: need trajectory files ${TRAJ}.cfl and ${TRAJ}.hdr." >&2; exit 1; } echo ">> Non-Cartesian path (trajectory supplied): gridded calibration + PICS -t." echo " This is a sensible default; verify it suits your trajectory/data." # Use the INVERSE nufft, not the adjoint: the adjoint leaves the sampling # density in the data (for radial, density ~ 1/|k|), so FFT-ing it back to a # grid hands ESPIRiT systematically mis-weighted k-space and biases the maps. # If BART cannot infer the image size here, pass -d X:Y:Z explicitly. bart nufft -i "$TRAJ" "$KSP" "${TMPBASE}_cimg" bart fft -u 7 "${TMPBASE}_cimg" "${TMPBASE}_gridksp" bart ecalib -m1 -r 24 "${TMPBASE}_gridksp" "${OUT}_sens" bart pics -l1 -r "$REG" -t "$TRAJ" "$KSP" "${OUT}_sens" "$OUT" else echo ">> Cartesian path (no trajectory): ESPIRiT + L1-wavelet PICS." bart ecalib -m1 -r 24 "$KSP" "${OUT}_sens" bart pics -l1 -r "$REG" "$KSP" "${OUT}_sens" "$OUT" fi echo ">> Done. Reconstructed image: ${OUT}.cfl/.hdr (coil maps: ${OUT}_sens)." echo ">> Output dimensions (dim 3 = 1 coil, dim 4 = 1 map if this went right):" bart show -m "$OUT" echo " Tune -r (arg 3, default ${REG}): raise if aliasing remains, lower if" echo " the image looks over-smoothed."
-
-
SKILL.md 8 KB
--- name: mri-reconstruction description: >- Actionable MRI image reconstruction — turn raw k-space into an image, and actually run it. Use this WHENEVER the user wants to reconstruct MR data or says things like "reconstruct this k-space", "run BART on this", "get an image from this .cfl / .h5 / twix file", or asks about parallel imaging (ESPIRiT/SENSE/GRAPPA), compressed sensing (PICS / L1-wavelet), coil sensitivity estimation, coil combination, or non-Cartesian / NUFFT reconstruction. This agent prefers to EXECUTE the reconstruction with BART or SigPy (not just describe it). It covers classical/analytic reconstruction — for anything TRAINED (unrolled networks, VarNet, self-supervised, diffusion priors, fastMRI models) hand off to the deep-learning-recon skill. Triggers: k-space, coil sensitivities, ESPIRiT, PICS, undersampled reconstruction, radial/spiral recon, `.cfl`/`.hdr`, ISMRMRD, Siemens twix, GE P-file. metadata: author: Ke Wang version: "0.7.0" --- # MRI Reconstruction (actionable) You are a reconstruction engineer: given k-space, produce an image — and run the pipeline, don't just talk about it. Default to **BART** (battle-tested, CLI, scriptable); use **SigPy** when the user is in Python. Confirm the data before running, then execute and inspect. ## Papers and textbooks See the [annotated reading list](references/reading-list.md) for primary papers, textbooks, publication details, direct source links and what each source supports. Use the [repo-wide reference index](../../REFERENCES.md) to navigate across skills. When using a method, cite its specific source; distinguish paper evidence from software instructions and current venue/safety requirements. ## Project research memory For project experiments, read `.mri-research/INDEX.md` when present and retrieve only relevant preferences, environment notes and evidence-linked lessons. After meaningful runs or corrections, record outcomes, failures, limitations and next steps; revise scoped lessons without erasing history. Keep user preferences separate from scientific findings. Use the [project memory workflow](../mri-research/references/project-memory.md) to initialize the folder or connect project `CLAUDE.md` / `AGENTS.md`. If the hub is absent, retrieve the reference from the official skill repository. ## Tool setup before execution For any application this skill uses, check for a compatible installation and follow the official upstream's setup instructions. Within the authorized task, install missing dependencies yourself in an isolated environment, run a small upstream example, then execute the user's workflow. Do not leave routine setup to the user or replace a missing tool with a homemade numerical implementation. Use established simulators/solvers; write only necessary configuration and glue. If blocked, report the actual obstacle and an established alternative. Read the [tool setup guide](../mri-research/references/tool-setup.md) when installing, repairing, or choosing an execution environment. If the hub is not installed, retrieve that reference from the official `KeWang0622/mri-research-skill` repository. ## Workflow **0. Identify the k-space format** (ask or inspect). BART works in its own `.cfl`/`.hdr`, so other formats need a conversion step: - **BART `.cfl` + `.hdr`** — native; dims must be `[X Y Z COILS ...]` (coils on dim 3). Ready to use. - **Siemens twix `.dat`** — `bart twixread -A meas.dat ksp` writes a `.cfl` (`-A` auto-guesses the dimensions; without it you must supply them explicitly via `-x/-y/-z/-c/-s/-n`, and a flagless call will not work). Then confirm with `bart show -m ksp`. Alternative: read in Python with `twixtools`/`pymapVBVD` and write a `.cfl`. - **NumPy array** — write a `.cfl` with BART's Python helper: `PYTHONPATH=$TOOLBOX_PATH/python python -c "import cfl; cfl.writecfl(name, arr)"` (`cfl.py` ships in BART's `python/` directory — it is not on PyPI, and the unrelated `bartpy` package on PyPI is a decision-tree library, not this). Make sure coils land on dim 3. - **ISMRMRD `.h5`** — BART *has* an `ismrmrd` tool, but it is a build-time option: the Makefile defaults to `ISMRMRD=0`, so a stock build has no `bart ismrmrd` command. Check with `bart ismrmrd -h`; if it's missing, either rebuild BART with `ISMRMRD=1` (needs the ISMRMRD C++ library) or read the file with the Python `ismrmrd` package and `cfl.writecfl`. Vendor raw → ISMRMRD first via `siemens_to_ismrmrd` / `ge_to_ismrmrd` / `philips_to_ismrmrd`. **1. Estimate coil sensitivities (ESPIRiT):** ``` bart ecalib -m1 -r 24 kspace sens ``` `-m1` matters: `ecalib` computes **two** ESPIRiT map sets by default, and `pics` then returns a soft-SENSE result with a size-2 MAPS dimension instead of a single image — a silent wrong answer. `-r` caps the auto-extracted calibration region (24³ is already the default; lower it if your ACS is smaller). **2. Reconstruct:** ``` # Fully sampled: inverse FFT + coil combine bart fft -iu 7 kspace img_coils && bart rss 8 img_coils img # Undersampled — parallel imaging + compressed sensing (the workhorse): bart pics -l1 -r 0.01 kspace sens img # l1-wavelet regularized ``` - **Non-Cartesian** (radial/spiral/cones/rosette): you also need the trajectory. Use `bart pics -t traj kspace sens img`. For calibration, grid with the **inverse** NUFFT (`bart nufft -i`), not the adjoint (`-a`) — the adjoint leaves the sampling density in the data and biases the ESPIRiT maps. Get the trajectory from the sequence/ISMRMRD, or `bart traj` for nominal. - **EPI is Cartesian.** Its zig-zag traversal still samples a Cartesian grid, so do *not* reach for a trajectory/NUFFT. EPI needs ramp-sampling regridding and Nyquist-ghost / phase correction first, then the Cartesian path above; geometric distortion is corrected downstream (topup/FUGUE). **3. Inspect:** check image dimensions, scaling, and orientation; look for residual aliasing (raise `-r`), over-smoothing (lower `-r`), or coil-combination errors. ## Runnable helper `scripts/bart_recon.sh <kspace_cfl> <output_cfl> [l1_reg] [traj_cfl]` runs an ESPIRiT → PI+CS pipeline on a BART `.cfl` k-space file. It **assumes Cartesian data with coils on dim 3 and a fully-sampled ACS** (calibration region); pass a **trajectory `.cfl`** as the 4th argument for genuinely non-Cartesian sampling (radial/spiral/cones/rosette — not EPI, which is Cartesian). It warns about these assumptions but can't fully verify them — check the header and adapt the regularization / calibration size to the data. ## SigPy (Python) alternative ```python import sigpy as sp, sigpy.mri as mr maps = mr.app.EspiritCalib(ksp).run() # coil maps img = mr.app.L1WaveletRecon(ksp, maps, lamda=0.01).run() # PI + CS # non-Cartesian: build a NUFFT from coords, use mr.app.SenseRecon ``` ## Guardrails - Confirm the acceleration factor and sampling (Cartesian vs non-Cartesian) before choosing a method — the wrong forward model gives garbage. - If BART isn't installed: https://codeberg.org/mrirecon/bart (source, active) with docs at https://mrirecon.codeberg.page/ — install and validate it when needed. If blocked, explain the limitation before switching to SigPy. Note the `github.com/mrirecon/bart` mirror is archived as of 2026. - **Report the SNR cost, not just the image.** Acceleration R costs SNR by `g·√R`; quote a g-factor (or a pseudo-replica SNR estimate for GRAPPA/ESPIRiT/ nonlinear recon) rather than implying R is free. - **Stay in lane:** anything trained — unrolled networks, VarNet/MoDL, SSDU, diffusion priors, fastMRI baselines — belongs to the `deep-learning-recon` skill. Designing the *acquisition* or the trajectory belongs to `pulse-sequence-design`; this skill consumes a trajectory, it doesn't design one. - For method theory and citations, see the hub: https://github.com/KeWang0622/mri-research-skill/blob/main/skills/mri-research/references/recon-methods.md and tool details at https://github.com/KeWang0622/mri-research-skill/blob/main/skills/mri-research/references/tools.md
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.