PyCSEMRI: Portable Python Package for Water-Fat Separation in CSE-MRI
Overview
PyCSEMRI is a Python package for water-fat separation in Chemical Shift Encoded MRI (CSE-MRI). It provides fast and robust estimation of proton density fat fraction (PDFF), R2*, and field maps.
Key features:
- Includes both graph-cut and LUT-based (
VARPRO_LUT) algorithms VARPRO_LUTachieves ~30% of the computation time of graph-cut with reduced water-fat swapping artifacts (validated on 100 patient cases)- C++ core using header-only libraries (Eigen, Boost) — no system-level dependencies or admin permissions required
- Both Python and MATLAB interfaces
- Pre-compiled PyPI wheels for easy installation, including offline environments (clinical scanners)
Background
The graph-cut algorithm is the most common approach for water-fat separation due to its robustness, particularly in the liver where off-resonance distributions can be complicated. However, it is computationally costly, and existing toolboxes depend on MATLAB and C++ libraries that require admin permissions — making deployment on clinical scanners (no internet, no root access) very challenging.
PyCSEMRI addresses these limitations by introducing the VARPRO_LUT algorithm and by using only header-only C++ libraries for maximum portability. This package builds upon the algorithms from the ISMRM Fat-Water Separation Workshop.
Installation
From PyPI (Recommended)
pip install pycsemri
From Source
Requires a C++ compiler and CMake.
git clone https://github.com/dtamadauw/PyCSEMRI_fast.git
cd PyCSEMRI_fast
pip install .
Offline Installation (Clinical Scanners)
For environments without internet access:
- On a machine with internet:
mkdir wheelhouse pip download pycsemri -d wheelhouse
- Transfer the
wheelhousefolder to the scanner. - Install:
pip install pycsemri --no-index --find-links=wheelhouse
Usage
import numpy as np
from pycsemri.VARPRO_LUT import VARPRO_LUT
# Prepare image data (nx, ny, nTE) and echo times
images = ... # complex-valued numpy array
tes = np.array([1.2, 2.4, 3.6, 4.8, 6.0, 7.2]) * 1e-3
imDataParams = {
'images': images,
'TE': tes,
'FieldStrength': 3.0,
'PrecessionIsClockwise': 1
}
algoParams = {
'SUBSAMPLE': 4,
'range_fm': [-200, 200],
'NUM_FMS': 41,
'range_r2star': [0, 100],
'NUM_R2STARS': 11,
'species': [
{'relAmps': [1.0], 'frequency': [0.0]}, # Water
{
'relAmps': [0.087, 0.693, 0.128, 0.004, 0.039, 0.014, 0.035],
'frequency': [-3.8, -3.4, -2.6, -1.9, -0.5, 0.5, 0.6]
} # Fat
]
}
results = VARPRO_LUT(imDataParams, algoParams)
See the Example_*.py files for detailed examples with HDF5 and DICOM data.
Dependencies
- Python: numpy, scipy, pydicom
- C++ (header-only, bundled automatically): Eigen, Boost
Contributing
See CONTRIBUTING.md for guidelines on reporting bugs and submitting pull requests.
License
Mozilla Public License 2.0 (MPL 2.0). See LICENSE.md.
References
- Hernando D, Kellman P, Haldar JP, Liang ZP. Robust water/fat separation in the presence of large field inhomogeneities using a graph cut algorithm. Magn Reson Med. 2010;63(1):79-90. doi:10.1002/mrm.22177
- Hu HH, Börnert P, Hernando D, et al. ISMRM Workshop on Fat-Water Separation. Magn Reson Med. 2012;68(2):378-388. doi:10.1002/mrm.24369
- ISMRM Fat-Water Separation Challenge
Release files for pycsemri 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 81.3 MB
Release files / pycsemri-0.2.5-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | pycsemri-0.2.5-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 7.3 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
012566ad4038bb0fd1e4959d6921e5125c95483c267fa8a5c44174e7458f7b01
|
|
BLAKE2b-256 checksum How to use checksums |
0d886c442c0e0100b24349fec03e5987058663773ece8d5fbce428a5d1d0c45c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycsemri-0.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pycsemri-0.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.8 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
64b9f3d92ff97255d6a2c555dcdfdc7f93ccb16ba77bca78fb8f0b99961c0bc5
|
|
BLAKE2b-256 checksum How to use checksums |
82c3a1c1e8ce0b4a2ac6707f8a7c3b0bb854adde1716f1195f78fb824da64a4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycsemri-0.2.5-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | pycsemri-0.2.5-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 751.4 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
3714f66a9fb35c2838bcb9c3f79b3661598343ccda5130fd2c29b9015ab1874f
|
|
BLAKE2b-256 checksum How to use checksums |
d8fba897b8b14ab71d195d0a496b5dcf60045afca58621904ca4d70f83baf1bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycsemri-0.2.5-cp311-cp311-musllinux_1_2_x86_64.whl
| Download URL | pycsemri-0.2.5-cp311-cp311-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 7.3 MB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
9d9dd7a10ec531852a3fc2f2f943dd54ba82d0689abefec9277747d4a8851edd
|
|
BLAKE2b-256 checksum How to use checksums |
3a209da19846209acbd2034e3efaa1633d5e4e883f54ca8812d88e94f6cf40fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycsemri-0.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pycsemri-0.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.8 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
5f1ac3a6b186c7642ffae699ab4b01e7f2b018d999eaf12819a601b44b02fc6b
|
|
BLAKE2b-256 checksum How to use checksums |
97929e146f410e1d096eb45f9251ab0359b2c2bd9023644d74838b64fb8d8f6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycsemri-0.2.5-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | pycsemri-0.2.5-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 751.4 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
44afc5cc09a71256ede2579f8563796be92439775d0bf5d83cffc5fdcda3dcd3
|
|
BLAKE2b-256 checksum How to use checksums |
4ea91b9f0fa346d55967d7e1be28d256a4d0ba6b790e714aa0482edf4696f7f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycsemri-0.2.5-cp310-cp310-musllinux_1_2_x86_64.whl
| Download URL | pycsemri-0.2.5-cp310-cp310-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 7.3 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
9ee81767df99512f89089a7edab7b2b2330425f08b29fd543d973661f7fce8d2
|
|
BLAKE2b-256 checksum How to use checksums |
242b90a4305e277ead9c71226b1e35e30bcd951b215065837b62bb2d56cf8d53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycsemri-0.2.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pycsemri-0.2.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.8 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
e3aeba097848945936366cf7f91aa52b2e337ec6f41a9a0842a285401966df1c
|
|
BLAKE2b-256 checksum How to use checksums |
b77870dc994974fbe3fcf1ba8b6d42ed53fc43032f6cda8c7caa9680987c3d9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycsemri-0.2.5-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | pycsemri-0.2.5-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 751.4 kB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a4340e7c58620fe10dc56f42fae1a65ec47e8f27ac4e49dbe95e05ed8ac3361c
|
|
BLAKE2b-256 checksum How to use checksums |
2b128359654cda135a659c87c6a3ea4ad391037b3109f493220e0f1e7188cda1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycsemri-0.2.5-cp39-cp39-musllinux_1_2_x86_64.whl
| Download URL | pycsemri-0.2.5-cp39-cp39-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 7.2 MB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
dabc0cc3878e5621aa452e35f15b992a9caad7569c79d5518f202762905f28cf
|
|
BLAKE2b-256 checksum How to use checksums |
a6ab3492dd0752a224766f797ea02ae662c3c3273aed169e23edafbb28bd1ae2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycsemri-0.2.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pycsemri-0.2.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.8 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
2e2f1fb52e9493fd52250bb417677057bd05a6cb5840cd7f60aa946e35188643
|
|
BLAKE2b-256 checksum How to use checksums |
2b75c138f02ee365281c31753cfdabb9fa186d8d51480a2cb366a442368e98ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycsemri-0.2.5-cp39-cp39-macosx_11_0_arm64.whl
| Download URL | pycsemri-0.2.5-cp39-cp39-macosx_11_0_arm64.whl |
|---|---|
| Size | 751.4 kB |
| Tags | CPython 3.9 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
7f9cb647d919b4d1fe7c8ea607dd9d345c243bb2c9bb49f7c4d4dd54f3bb72a9
|
|
BLAKE2b-256 checksum How to use checksums |
ee0683dc1470919f76ab155372718a0fedb660dd28cde3730d1071120e1fdedb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycsemri-0.2.5-cp38-cp38-musllinux_1_2_x86_64.whl
| Download URL | pycsemri-0.2.5-cp38-cp38-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 7.2 MB |
| Tags | CPython 3.8 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
79dfcc2d9e952317e26ac5b2fe843503d9c2c233f671e65e9926ae6296d5920c
|
|
BLAKE2b-256 checksum How to use checksums |
38c4c3cd7526cf09e5bf453e0fa7a79dff6d9196747bf54f4f2f61eb18264d38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycsemri-0.2.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pycsemri-0.2.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.8 MB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
23ec0d85ad2133e457b98516ad55c80eaa7178341b394f6763e4e0b26d8c708a
|
|
BLAKE2b-256 checksum How to use checksums |
854531dfda8d47a6c8c02d4eeb4be58069ad7dda2b69290b900d9152f2e0a518
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycsemri-0.2.5-cp36-cp36m-musllinux_1_2_x86_64.whl
| Download URL | pycsemri-0.2.5-cp36-cp36m-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 7.2 MB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
e48cb832840d11a5ca7f8ed827577bc4608c8ff6d6bfb9aff6923129f0e53539
|
|
BLAKE2b-256 checksum How to use checksums |
4f173ece62fc18c6caddd444d290b3f9f56574281533f0cee90a733781ea3790
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pycsemri-0.2.5-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pycsemri-0.2.5-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 5.8 MB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
ca013db8a022de298b19ff139c971cbd15ac0b6c4869fe21ab1b83d9df6d7424
|
|
BLAKE2b-256 checksum How to use checksums |
7a7ed1e12ed3740f1b71aa7f93b0b39425efffb3b5f12a83553a0b998abfe24e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|