Skip to main content

Statistical single-exposure retrieval of transmission, isotropic and directional dark-field signals for X-ray imaging

Project description

🌀 SerPy — Statistical single-exposure Retrieval of directional dark-field in PYthon

PyPI version Python versions License: MIT Status


SerPy implements a statistical single-exposure framework for retrieving transmission, isotropic dark-field, and directional dark-field (DF) signals from a single pair of images (reference and sample).
It is compatible with both modulation-based, speckle-based, single grid, edge illumination, and grating-based X-ray imaging techniques.


🚀 Overview

Conventional dark-field imaging requires multiple phase steps or modulator positions to separate phase, absorption, and scattering information.
SerPy eliminates this need by relying on local contrast statistics computed within small sliding windows.
From these statistics, the method reconstructs the directional scattering ellipse at each pixel, yielding quantitative maps of:

  • Transmission $ T(\mathbf{r})$
  • Isotropic dark-field $ D_f(\mathbf{r}) $
  • Directional dark-field: orientation, anisotropy, and magnitude

✳️ Key Features

  • 🔹 Single-exposure retrieval — no phase stepping or mask motion required
  • 🔹 Local statistical analysis of contrast anisotropy
  • 🔹 Directional dark-field extraction via ellipse fitting in polar space
  • 🔹 Orientation smoothing using circular Gaussian filtering
  • 🔹 Vectorized & Numba-accelerated kernels for high performance
  • 🔹 Compatible with modulation-based, speckle-based, single grid, edge illumination, grating-based setups

⚙️ Installation

⚠️ Important — Create a dedicated Python environment

SerPy-X relies on numba, which is not yet compatible with Python 3.14.
Therefore, it is strongly recommended to install SerPy-X inside a dedicated environment
using a compatible Python version (≥3.9 and <3.14), for example Python 3.12.


▶️ Option 1 — Install from PyPI (recommended)

🔹 Using conda

conda create -n serpy-env python=3.12
conda activate serpy-env

pip install serpy_x

🔹 Using venv (standard virtual environment)

python3.12 -m venv serpy-env
source serpy-env/bin/activate

pip install --upgrade pip
pip install serpy_x

▶️ From source

git clone https://github.com/MuguiwaraSamy/SerPy.git
cd SerPy

# Create a compatible Python environment first
conda create -n serpy-dev python=3.12
conda activate serpy-dev

pip install --upgrade pip
pip install -e .    

🧠 Quickstart Example

import numpy as np
from Serpy.statdf import retrieval_Algorithm

# img, ref : 2D numpy arrays (sample and reference)
out = retrieval_Algorithm(img, ref, n_angles=19, window_size=5)

Key Description
angles Array of sampled orientation angles (in radians) used for the directional analysis
T Transmission map ( T(\mathbf{r}) )
Non-oriented Df Isotropic dark-field (scalar visibility loss)
Oriented Df Directional dark-field profiles sampled along each orientation ((H, W, N_\theta))
major axis Semi-major axis of the fitted ellipse (maximum scattering direction)
minor axis Semi-minor axis of the fitted ellipse (minimum scattering direction)
Orientation Raw ellipse orientation (principal scattering direction, before smoothing)
Corrected Orientation Smoothed and π-periodic orientation map
saturation Local angular coherence or stability of the orientation field
(optionally) mean_s, std_s, mean_r, std_r Intermediate directional statistics (sample/reference means and standard deviations), included if return_intermediates=True

📘 Full Example Notebook

A complete, end-to-end demonstration of the SerPy-X pipeline is provided in: /examples/exemples.ipynb


⚠️ Patent Notice

A patent application covering the underlying method and algorithm has been filed by the author(s): "Procédé d’imagerie et produit programme d’ordinateur correspondant", filed on September 26, 2025.

The publication of this code under the MIT license does not grant any license or rights to practice the patented invention.
Use of this software for research and non-commercial purposes is permitted under the terms of the MIT License.
Any commercial use of the patented method requires a separate license from the patent holder.

📜 License

Distributed under the MIT License. © 2025 Samy Kefs. All rights reserved.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

serpy_x-0.1.4.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

serpy_x-0.1.4-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file serpy_x-0.1.4.tar.gz.

File metadata

  • Download URL: serpy_x-0.1.4.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for serpy_x-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2c4332d21e4134ab2e1ea02327dbc1620b1132bb2725f8e78b58f5cfd00cf20a
MD5 61641d89be18e11d85a8877f029970b7
BLAKE2b-256 4216c9d3ec48862a125d2b0f6e8e4c8cdf3d2778c08bdb2376d248b1a00b7f69

See more details on using hashes here.

File details

Details for the file serpy_x-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: serpy_x-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for serpy_x-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fa3a8a488e9c72911bb55c1646dc93709e5b2ad6682cd9ca52f65242e1d4545f
MD5 997e2ed408deee948065056e7ed8a71f
BLAKE2b-256 cfb22c56d805048ef81ce11071d5c9f732f7363531532a95b517d3e1966685b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page