Skip to main content

Bayesian MEF

PyPI Python 3.9+ DOI License

Bayesian multi-exposure image fusion (MEF) is a general-purpose algorithm to achieve robust high dynamic range (HDR) imaging, particularly in scenarios with low signal-to-noise ratio (SNR) or variations in illumination intensity. This approach is especially crucial for high quality phase retrieval in coherent diffractive imaging (CDI). The algorithm, detailed in the arXiv preprint, primarily focuses on its implementation and demonstrates the benefits in ptychography. To reproduce the results in the paper, see this section. However, to get started, please install the package and check the demo usage below.

demo_mef

To install this package from PyPI,

pip install bayes_mef

Usage

A minimal example demonstrating the usage of BayesianMEF by simulating some data.

Open In Colab

from bayes_mef import BayesianMEF
from skimage.data import camera
import numpy as np

# simulation params
truth = camera()
background = 60  # some background
times = np.array([0.1, 1, 10])  # exposure times or equivalently flux factors
threshold = 1500 # detector limit

# poisson data based on image formation model that is overexposed
data = [np.random.poisson(time * truth + background) for time in times]
data_saturated = np.clip(data, None, threshold, dtype="float")

# Bayesian MEF with optional field `update_fluxes`. Set it to `True` when
# flux factors (exposure times) are not accurately known.
mef_em = BayesianMEF(data_saturated, threshold, times, background, update_fluxes=False)
mef_em.run(n_iter=100)
fused_em = mef_em.fused_image.copy()

Additionally, one can also use the ConventionalMEF method as given in the paper.

from bayes_mef import ConventionalMEF
mef_mle = ConventionalMEF(data_saturated, threshold, times, background)
mef_mle.mle()
fused_mle = mef_mle.fused_image.copy()

Parallelized implementatation

In ptychography, one needs to fuse diffraction patterns for every scan position. Processing this for data over all scan positions can be slow for an iterative algorithm. Therefore, one can use the parallelized implementation for MEF LaunchMEF. Check the example below

from bayes_mef import LaunchMEF

launch_mef = LaunchMEF(
    ptychogram_stack,    # ptychogram shape (n_exposures, n_scans, dp_x, dp_y)
    background,          # background shape (n_exposures, n_scans, dp_x, dp_y)
    flux_factors=None,   # if set to `None`, calculates automatically
    threshold=None,      # if set to `None`, calculates automatically
    update_fluxes=False, # set to `True` if you want to update fluxes
)

# runs Bayesian MEF in parallel by defining the number of CPUs `n_cpus`;
# returns the fused diffraction patterns with shape (n_scans, dp_x, dp_y) and updated flux factors
n_cpus = 20
n_iter = 150
fused_ptyem_stack, em_flux_factors = launch_mef.run_em(n_iter, n_cpus)

For a detailed usage, please check synthetic_mef.py that uses synthetic ptychography data.

Reproducing results

To reproduce the ptychographic reconstruction results from the paper, please follow the below steps:

  1. Please clone this repository and create a conda environment.

    git clone https://github.com/microscopic-image-analysis/bayes-mef.git
    cd bayes-mef
    conda create --name bayes-mef-venv python=3.11.5 
    
  2. Now activate the environment and install the pinned dependencies.

    conda activate bayes-mef-venv
    pip install -r requirements.txt
    
  3. Download the data from Zenodo with the following command:

    ./download_data.sh
    
  4. Optional: For faster ptychographic reconstructions using GPU, please install cupy as given under its installation guide.

  5. Run files from the scripts/ directory for plotting the results.

Citation

If you found this algorithm or the publication useful, please cite us at:

@misc{Kodgirwar:24,
      title={Bayesian multi-exposure image fusion for robust high dynamic range ptychography}, 
      author={Shantanu Kodgirwar and Lars Loetgering and Chang Liu and Aleena Joseph and Leona Licht
              and Daniel S. Penagos Molina and Wilhelm Eschen and Jan Rothhardt and Michael Habeck},
      year={2024},
      eprint={2403.11344},
      archivePrefix={arXiv},
      primaryClass={eess.IV}
}

Download files

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

Source Distribution

bayes_mef-0.1.7.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

bayes_mef-0.1.7-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file bayes_mef-0.1.7.tar.gz.

File metadata

  • Download URL: bayes_mef-0.1.7.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.5 Linux/6.5.0-28-generic

File hashes

Hashes for bayes_mef-0.1.7.tar.gz
Algorithm Hash digest
SHA256 a165f3937374e5c948f509ea30c4c1b213c806749705003dc94a426dcebebbb3
MD5 cd039a222ca7595dbc16733f6d69b8d1
BLAKE2b-256 6a0499d3ee2c8adbd026ed6a68fc6cbe59d1be842a40ae50d0263ff898453c7b

See more details on using hashes here.

File details

Details for the file bayes_mef-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: bayes_mef-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.5 Linux/6.5.0-28-generic

File hashes

Hashes for bayes_mef-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1f2e51325bb584ec657d62106208e827887e92a024af5b1567627e2770d23a4d
MD5 3067a3e9fff4e29d5e47371b0895c296
BLAKE2b-256 7e23599a5d1e5ad9a3513a1efaced693e8c6d85ec1ae014e6a2e782a4cbb3766

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.0

2 files

0.1.9

2 files

0.1.8

2 files

This release

0.1.7 This release

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

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