Self-Supervised Motion Artifact Rating for MR Images Using Angular Contrastive Learning
In this work, we present a self-supervised framework that can quantify motion artifact severity on magnetic resonance images. Our model learns to encode image artifact severity as angular distances from the anchor embeddings. Our self-supervised learning approach does not require manual labeling on artifact severity. Our approach systematically simulates a continuous range of motion artifacts via controlled k-space corruptions and leverages LPIPS as a perceptual metric to guide and fine-tune the pretrained DINOv2 model using angular contrastive loss. The resulting embeddings reflect artifact severity in a perceptually aligned, interpretable manner. Beyond accurately differentiating a smooth spectrum of artifact severity, our method generalizes to unseen modalities, demonstrating zero-shot adaptation to images of different tissue contrast. It also extends naturally to other quality degradations, including inhomogeneity and noise.
Installation
# Clone the repository
git clone https://github.com/jinghangli98/sphereMRI.git
cd sphereMRI
# Install the package
pip install -e .
Usage
Rating a NIfTI image
The main functionality is to rate the quality of a NIfTI image. Simply use the rate command:
# Basic usage (for TSE images - default)
rate -i path/to/your/image.nii.gz
# For T1 images
rate -i path/to/your/T1_image.nii.gz --t1
# Example with a specific reference directory and output directory
rate -i path/to/your/image.nii.gz -r reference_images/ -o results/
Command Line Arguments
-i, --input: Input NIfTI file to rate (required)-r, --reference-dir: Directory with reference quality images (optional, will use built-in reference if not provided)-o, --output-dir: Output directory for detailed results-c, --checkpoint: Path to model checkpoint (optional, will use built-in model if not provided)--contrastive: Contrastive method (angular or euclidean, default: angular)--slice-idx: Slice index (automatically set based on contrast: -1 for TSE, 1 for T1 if not specified)--num-anchor-images: Number of anchor images to use (default: 5)--cpu: Force CPU usage instead of GPU--t1: Use T1 contrast mode instead of default TSE mode
How It Works
The NiftiQualityRater works by:
- Loading a DinoV2 small ViT model for embedding MRI images
- Creating a reference embedding from high-quality images
- Comparing new images against this reference embedding
- Scoring images based on their similarity to the reference
Quality scores range from 0.0 to 1.0, where higher scores indicate better quality.
Contrast Modes
The tool supports two contrast modes:
- TSE (default): For Slanted Turbo Spin Echo type sequences, use slice_idx=-1.
- T1: For T1-weighted images. Uses coronal slices (slice_idx=1).
Each mode uses a different pre-built anchor embedding that was trained on high-quality images of that contrast. To specify T1 mode, use the --t1 flag.
Metadata
Release files for spheremri 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spheremri-0.1.0.tar.gz | 82.1 MB | Without provenance | Details for spheremri-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spheremri-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for spheremri-0.1.0-py3-none-any.whl |
Total release size: 164.2 MB
Release files / spheremri-0.1.0.tar.gz
| Download URL | spheremri-0.1.0.tar.gz |
|---|---|
| Size | 82.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f493d8f81bc2caeb6b7527ef4535eab30e4fe710af76fccc2364bea86fe5901
|
|
BLAKE2b-256 checksum How to use checksums |
23412c68112c9ff01ba28386e5a898b27e3588f0312c8696a4941a20c5c89bea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.16
|
Release files / spheremri-0.1.0-py3-none-any.whl
| Download URL | spheremri-0.1.0-py3-none-any.whl |
|---|---|
| Size | 82.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f57bf24605f0d17b3444494f2ef2b003669eb5ea241aace5eb6559962d79e103
|
|
BLAKE2b-256 checksum How to use checksums |
b1005d2b268bdf1ff95b0ee7890be18b04f0c2fca363c1eb4f302fe92ece5192
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.16
|
Security for spheremri 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.
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.