Skip to main content

LOFI

Low-Field MRI corruption. LOFI makes good scans look like low-field open-magnet scans, for training models that must work on the bad ones. It only changes intensities, so anatomy stays where it is and labels stay exact.

Branch CI

Status: pre-release.

Install

pip install lofi-aug            # core
pip install "lofi-aug[io]"      # NIfTI support (needed by the command line)

Other extras: viz, monai, torchio.

How it works

A forward model runs in acquisition order, so the artefacts emerge rather than being painted on:

  1. Normalise and map contrast. The foreground median becomes 1. An optional monotonic map moves the tissue histogram to the target's.
  2. Frame. Pad to the scanner's canvas.
  3. Select slices. Box-average thick slabs. Each acquisition's slabs can be displaced.
  4. Shade. Multiply by a smooth receive sensitivity.
  5. Sample k-space. Add a smooth phase, then crop k-space to the acquired matrix with a taper.
  6. Corrupt k-space. Add line-by-line phase errors (ghosting), optional EMI tones, then complex noise, less what the source already carries at that voxel size.
  7. Magnitude. This is where the Rician floor comes from.
  8. Resample and combine. Linear onto the output grid, then average the acquisitions.
  9. FOV. Warped edge, exact zeros outside it, and a fade towards it.

Scanner-specific choices live in profiles. low_field_breast is bundled and fitted to real scans.

Command line

lofi profiles
lofi corrupt good.nii.gz --label good_label.nii.gz --profile low_field_breast --n 4 --out out/
lofi measure scan_*.nii.gz
lofi calibrate --target bad_*.nii.gz --sources good_*.nii.gz --out my_scanner.yaml

Python

from lofi.augment import LowFieldCorrupt

corrupt = LowFieldCorrupt("low_field_breast", seed=0)
sample = corrupt({"image": image, "label": label, "spacing": (0.8, 0.8, 1.1)})  # (C, *spatial)

The result also holds "fov", and "spacing" becomes the output grid's. Labels are moved onto that grid with the image and set to background outside the FOV.

Framework adapters keep the input grid, since those pipelines fix it themselves. Apply them before random cropping:

  • MONAI: lofi.integrations.monai.LowFieldCorruptd(["image", "label"], "low_field_breast").
  • TorchIO: lofi.integrations.torchio.RandomLowField("low_field_breast").

With raw k-space and a noise-only scan, lofi.physics.corrupt_kspace applies the field-strength model directly, including the separate scaling of coil and sample noise.

Development

uv sync --extra dev --extra io
uv run pytest
uv run ruff check . && uv run ruff format --check .
uv run mypy

CLAUDE.md records the conventions and the design as built. The research behind the package (calibration study, research notes, downstream segmentation studies) is kept outside it, in the _lofi folder of lochungtin/PhD_Codebase.

Licence

MIT.

Metadata

Release files for lofi-aug 0.1.0

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

Source distribution (sdist)

Source distribution for lofi-aug 0.1.0
File Size Uploaded Provenance Actions
lofi_aug-0.1.0.tar.gz 285.8 kB With provenance Details for lofi_aug-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lofi-aug 0.1.0
File Interpreter ABI Platform Actions
lofi_aug-0.1.0-py3-none-any.whl Python 3 none any Details for lofi_aug-0.1.0-py3-none-any.whl

Total release size: 315.8 kB

Release files / lofi_aug-0.1.0.tar.gz

Download URL lofi_aug-0.1.0.tar.gz
Size 285.8 kB
Tags Source
SHA-256 checksum
How to use checksums
43226e837416cc6794c682acd7fab840b879f3f43a672abb20b8c6b194da11a3
BLAKE2b-256 checksum
How to use checksums
62b0592e0a55489e5223d124bff9601168154c9e896ebcdd7ae41f3eb02b5ee3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / lofi_aug-0.1.0-py3-none-any.whl

Download URL lofi_aug-0.1.0-py3-none-any.whl
Size 29.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4636496461d6d4ef0abe06747faa3144b414a3a220167f4b1d29ddf278841b60
BLAKE2b-256 checksum
How to use checksums
51b54501ee3b627a163cb3755f9780b729ab001278a9013e2738aec054729d8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for lofi-aug 0.1.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for lofi_aug-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

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

0.1.0 This release

2 release files Full 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