Skip to main content

MPRAGEise DOI

Background denoise MP2RAGE UNI images (MPRAGEising) whilst either removing or reintroducing the bias field - Powered by AFNI

Table of Contents

Usage

Preferred script: MPRAGEise.py
MPRAGEise.py is the Python implementation of the original shell script and is recommended for its easier interface and better logging capabilities.

Setup:

git clone https://github.com/srikash/MPRAGEise.git
cp MPRAGEise/MPRAGEise.py $HOME/abin

This install needs nothing beyond AFNI and the Python standard library. For -qc (below), either install its extra dependencies yourself (pip install nibabel matplotlib), or install the package instead: pip install mprageise[full].

Usage:

python MPRAGEise.py -i INV2_image.nii.gz -u UNI_image.nii.gz

Options:

Flag Description
-i, --inv2 MP2RAGE INV2 image (required)
-u, --uni MP2RAGE UNI image (required)
-r, --re_bias Reintroduce bias-field instead of removing it (default 0)
-o, --output Output folder (default: a new <UTC timestamp>_MPRAGEise_run folder next to the INV2 image)
-overwrite Pass -overwrite to every AFNI command
-afni-path Directory containing the AFNI binaries, checked before $AFNI_HOME and PATH
-v, --verbose Verbose logging
-qc Write a before/after QC PNG with normalised intensity histograms (needs pip install mprageise[full])
-version Print the version and exit

AFNI is located automatically, in order: -afni-path, $AFNI_HOME, a cached result from a previous run (.mprageise_afni_cache.json, next to the script; delete it if AFNI moves), PATH, and then common install directories (/opt/afni-latest, /opt/afni, and ~/abin, AFNI's own documented install locations). If none of those resolve, the script exits with a clear error instead of failing deep inside an AFNI call.

If -o names an existing, non-empty folder, -overwrite is enabled automatically for that run (with a warning) instead of failing partway through.

AFNI's own command output never reaches the screen. A live elapsed-time indicator shows per-step progress instead; pass -v to see the full command, stdout, and stderr for each step.

Intermediate files live briefly in a tmp_mprageise_<8-char hex> subfolder of the output folder, not the OS temp directory, so they share its filesystem. The subfolder is removed automatically when the run finishes or fails.

-qc writes <uni_basename>_qc.png into the output folder: a US Letter page with a centred, borderless 2x2 grid showing the UNI image before and after MPRAGEising (middle axial slice) with its normalised intensity histogram below (200 bins, clipped to the 0.05-99.5th percentile range, outline style in validated colours, y-axis in scientific notation). The two images are an exact 0.5cm apart, as are the two histograms (85% of the image size, with the "after" histogram's y-axis mirrored to its right edge); the histogram row sits a clear 1.5cm below the image row. The header names the MPRAGEise version and the UNI input file; the footer gives the UTC timestamp. Background is excluded from the histograms using a foreground mask derived from the raw INV2 image, before bias correction, via Otsu thresholding, since INV2's brain/background contrast is much cleaner than UNI's flat non-zero noise floor would otherwise allow.

Nota bene: Do not use this script for the MP2RAGE T1 map.

Development

uv sync --locked && uv run pytest

Tests run against a fake AFNI adapter and need no AFNI install (without uv, pip install pytest && pytest tests/ works too). CI (.github/workflows/ci.yml) runs the same suite across Python 3.12 and 3.13 on every push/PR, plus uv run ruff format --check, uv run ruff check, and uv run mypy ..

On every push to main, CI tags a new version from pyproject.toml (if it's changed) and triggers .github/workflows/release.yml, which publishes to PyPI via trusted publishing (no stored token) after confirming that version isn't already there.

Containerised usage

A Dockerfile is provided (built with neurodocker: Fedora 40 + AFNI binaries + Python 3.12), so no local AFNI install is required.

Build:

docker build -t mpragise .

Run:

docker run --rm -u $(id -u):$(id -g) -v /path/to/data:/data mpragise -i /data/inv2.nii.gz -u /data/uni.nii.gz -o /data/out

Nota bene: passing -u $(id -u):$(id -g) ensures output files in the mounted volume are owned by you, not the container's default user.

Expected result

Compared to the output of MP2RAGE Robust Background Removal MATLAB Script or MP2RAGE Robust Background Removal Python Script

Coronal Axial

Metadata

Release files for mprageise 1.9.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mprageise 1.9.2
File Size Uploaded Provenance Actions
mprageise-1.9.2.tar.gz 15.7 kB Without provenance Details for mprageise-1.9.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mprageise 1.9.2
File Interpreter ABI Platform Actions
mprageise-1.9.2-py3-none-any.whl Python 3 none any Details for mprageise-1.9.2-py3-none-any.whl

Total release size: 28.8 kB

Release files / mprageise-1.9.2.tar.gz

Download URL mprageise-1.9.2.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c8000d6acd88b614601b9d70ea261b8204bc2e3c62ba65eb53acd545f2247154
BLAKE2b-256 checksum
How to use checksums
0aab9364ac4dba9142ca1a48315b5890b68378456fa175ffead4a2e4c78b6860
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / mprageise-1.9.2-py3-none-any.whl

Download URL mprageise-1.9.2-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a213d50f0bccfd8b4067732ab81cd16a47758fb2489ff240f7119d5a624b6fba
BLAKE2b-256 checksum
How to use checksums
162f5f1f0e878a8e62b880ca479b6d6b5242c7d44482fb4c676958e51a2d1c1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for mprageise 1.9.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.9.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page