Metadata-Version: 2.4
Name: intensity-normalization
Version: 4.0.0
Summary: Normalize intensities of MR image modalities
Project-URL: Documentation, https://jcreinhold.github.io/intensity-normalization/
Project-URL: Homepage, https://github.com/jcreinhold/intensity-normalization
Project-URL: Issues, https://github.com/jcreinhold/intensity-normalization/issues
Project-URL: Repository, https://github.com/jcreinhold/intensity-normalization
Author: Jacob Reinhold
License: MIT License
        
        Copyright (c) 2025 Jacob Reinhold
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Healthcare Industry
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Image Processing
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Requires-Python: >=3.12
Requires-Dist: nibabel>=5.0.0
Requires-Dist: numpy>=1.24.0
Requires-Dist: scipy>=1.10.0
Requires-Dist: typer>=0.12.0
Provides-Extra: ants
Requires-Dist: antspyx>=0.4.0; extra == 'ants'
Provides-Extra: dev
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Requires-Dist: ty>=0.0.1a17; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9.5.0; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.26.0; extra == 'docs'
Provides-Extra: plot
Requires-Dist: matplotlib>=3.7.0; extra == 'plot'
Description-Content-Type: text/markdown

# intensity-normalization

[![PyPI](https://img.shields.io/pypi/v/intensity-normalization.svg)](https://pypi.org/project/intensity-normalization/)
[![Docs](https://img.shields.io/badge/docs-github%20pages-blue)](https://jcreinhold.github.io/intensity-normalization/)

Normalize the intensities of magnetic resonance (MR) images — T1-w, T2-w, FLAIR, PD-w — across scanners, sites, and
sessions.

MR images have no consistent intensity scale; the inconsistency is an acquisition artifact that breaks downstream
processing (especially ML). This package implements the standard fixes:

- **Individual methods** — `zscore`, `fcm`, `kde`, `whitestripe`: plain functions of one image.
- **Population methods** — `nyul`, `lsq`, `ravel`: learn a transform from a set of images; save it, apply it to new
  scans.
- **Tools** — tissue membership maps, histogram plotting (validation), N4 preprocessing, co-registration (ANTs).

## Install

```bash
pip install intensity-normalization            # or: uv add intensity-normalization
pip install "intensity-normalization[ants]"  # ravel registration, preprocess, coregister
pip install "intensity-normalization[plot]"  # histogram plotting
```

The CLI also runs without installing: `uvx intensity-normalize --help`.

## Quickstart

```python
import intensity_normalization as inorm

normed = inorm.whitestripe(t1w_image, mask=brain_mask)  # numpy or nibabel in → same type out

tx = inorm.nyul.fit(train_images, masks=train_masks)  # population: fit once...
tx.save("nyul.npz")
normed_new = tx(new_image)  # ...apply to new scans
```

```bash
intensity-normalize fcm t1w.nii.gz -m brain_mask.nii.gz -p
intensity-normalize nyul images/ -m masks/ -o normalized/ --save-state nyul.npz
```

**[Documentation](https://jcreinhold.github.io/intensity-normalization/)** —
[quickstart](https://jcreinhold.github.io/intensity-normalization/quickstart/),
[how-to guides](https://jcreinhold.github.io/intensity-normalization/how-to/),
[choosing a method](https://jcreinhold.github.io/intensity-normalization/methods/),
[algorithms](https://jcreinhold.github.io/intensity-normalization/algorithms/),
[CLI](https://jcreinhold.github.io/intensity-normalization/cli/),
[API](https://jcreinhold.github.io/intensity-normalization/api/),
[migrating to v4](https://jcreinhold.github.io/intensity-normalization/migration/).

## Reference

If you use this package, please cite the accompanying [pre-print](https://arxiv.org/abs/1812.04652):

```bibtex
@article{reinhold2019evaluating,
  title={Evaluating the impact of intensity normalization on MR image synthesis},
  author={Reinhold, Jacob C and Dewey, Blake E and Carass, Aaron and Prince, Jerry L},
  journal={Medical Imaging 2019: Image Processing},
  year={2019}
}
```

## License

MIT
