pyspeckle is a Python library for generating and analyzing laser speckle fields. It provides reproducible numerical implementations of physically motivated speckle models used in optical metrology, coherent imaging, and biomedical photonics.
The methods implemented in this package are derived from the algorithms of Duncan & Kirkpatrick ("Algorithms for simulation of speckle (laser and otherwise)", Proc. SPIE 6855, 2008). These algorithms unify a variety of simulation approaches across:
- objective speckle (non-imaged fields),
- subjective speckle (imaged fields),
- static speckle, and
- dynamic speckle including translation, strain, boiling, and decorrelation.
The goal of this project is to provide the research community with a reliable, transparent, and extensible computational reference for speckle simulation studies and validation of analytical models.
Coherent imaging systems—including SAR, OCT, ultrasound, ESPI, and laser speckle contrast imaging—produce granular interference patterns defined by the random phase relationships of scattered waves.
The statistical properties of these patterns depend on:
- the nature of the scatterers,
- the system geometry (objective vs. subjective speckle),
- sampling in the optical transfer function domain,
- polarization state,
- mechanical motion (coordinated or uncoordinated),
- temporal evolution of scatterer phase correlations.
Using the FFT-based band-limited generation approach described by Duncan & Kirkpatrick, this library supports:
- fully developed speckle following exponential intensity statistics,
- partially polarized speckle fields parameterized by polarization degree,
- correlation-controlled temporal sequences via Gaussian copulas,
- controlled motion using the Fourier shift theorem,
- simulation of decorrelation consistent with analytical expectation (e.g., Airy-law decay in defocus imaging).
The resulting fields are suitable for testing theory, validating algorithms, benchmarking imaging systems, and training machine-learning models under controlled statistical conditions.
Full documentation and algorithm demonstrations are available at:
https://pyspeckle2.readthedocs.io
A browser-run JupyterLite environment requires no installation:
https://scottprahl.github.io/pyspeckle/
pip:
pip install pyspeckle
or conda:
conda install -c conda-forge pyspeckle
If you use pyspeckle in research or publication, please cite:
Prahl, S. (2025). *pyspeckle: A Python module for creation and analysis of laser speckle.* Version 0.6.0. https://doi.org/10.5281/zenodo.8312075
Duncan & Kirkpatrick (2008) "Algorithms for simulation of speckle (laser and otherwise)", Proc. of SPIE Vol. 6855, 685505.
pyspeckle is released under the MIT License. Contributions are welcome.

