Skip to main content

Python implementation of computational optical propagation and digital holography.

Project description

Fringe.Py

A coherent propagation and diffraction simulation tool, all written in Python.

In this package, a set of utilities are provided to simulate coherent signal propagation. It is particularly made for free-space optical propagation, diffraction, and holography. However, the tools are compatible with 1D and 2D data structures and can be potentially used for any sort of spatially-coherent signals.


What's inside?

A set of modules are provided to solve the scalar diffraction problem. The codes are GPU-friendly, compatible with well-known computation libraries (Numpy, TensorFlow) and they support batch processing. Using the TensorFlow backend, computations become autograd-compatible and could be mounted on machine learning models. Angular spectrum algorithm is the primary work horse for field propagation though other custom solvers could be used. Aside the built-in Numpy and TensorFlow backends, any computational means could be employed to process tensor operations.

It also includes:

  • a simple yet useful data pipeline to load and standardize data. For now, it only supports images.
  • Gerchberg-Saxton multi-distance phase recovery algorithm. It can be easily tweaked to support other variations of signal e.g. by wavelength.

Installation

To install the package, run:

python -m pip install fringe

Fringe requires numpy, tensorflow 2.x, and scikit_image. The example files are not included in the package and should be downloaded separately. Also they require matplotlib to show plots.

How to Use

  1. Import or create data

For images:

import numpy as np
from fringe.utils.io import import_image
from fringe.utils.modifiers import ImageToArray, Normalize, MakeComplex

Images need to be standardized, normalized, and casted to complex data type. Modifiers are tools made for this purpose which apply these operations on import.

p1 = ImageToArray(bit_depth=16, channel='gray', crop_window=None, dtype='float32')
p2 = Normalize(background=np.ones((512, 512)))
p3 = MakeComplex(set_as='amplitude', phase=0)

obj = import_image("images/squares.png", preprocessor=[p1, p2, p3])
  1. Propagate

Solvers contain propagation algorithms and can be called by solver.solve. In particular, angular Spectrum algorithm convolves the input field with a free-space propagtor function which depends on wavelength λ (or wavenumber k=2π/λ) and distance z.

from numpy import pi, abs, angle
from fringe.solvers.AngularSpectrum import AngularSpectrumSolver as AsSolver

solver = AsSolver(shape=obj.shape, dr=1, is_batched=False, padding="same", pad_fill_value=0, backend="Numpy")
rec = solver.solve(hologram, k=2*pi/500e-3, z=-1000)
amp, phase = abs(rec), angle(rec)

ax = pyplot.sublots(2, 1, 1)
ax[0].imshow(abs(obj))
ax[1].imshow(amp)
pyplot.show()

Example notebooks provide further details with 1D and 2D diffraction, GPU acceleration, batch processing, and phase recovery.

License

Fringe is released under the MIT license. See LICENSE for details.

======= History

0.0.1 (2021-02-19)

  • First release on PyPI.

0.0.2 (2021-02-25)

  • Some bugs and errors fixed

0.0.3 (2021-02-25)

  • Minor bugs fixed

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

fringe-1.0.2.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

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

fringe-1.0.2-py2.py3-none-any.whl (17.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file fringe-1.0.2.tar.gz.

File metadata

  • Download URL: fringe-1.0.2.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.10

File hashes

Hashes for fringe-1.0.2.tar.gz
Algorithm Hash digest
SHA256 e5b601c0a4ac0bab95030aeead9fc8a6d0f58413919c0693c4cfa15a0db5bc33
MD5 2e19cf6fee65a45ec867c0d0640c8a0e
BLAKE2b-256 c5ac5998349f99f17558e78ca9888397c5f41ad79bf1605d0e85476bffb11d6f

See more details on using hashes here.

File details

Details for the file fringe-1.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: fringe-1.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.10

File hashes

Hashes for fringe-1.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cbc416f7dd5ae121e215665aa792e7359b7a2b7485bd88db9c98fd8acc1fac2e
MD5 326c25ff027709bd588dad221b83f127
BLAKE2b-256 eb35284ec25ce9dbb96baa9e94376490fc2dcf7b28c170d09c2b890fbb9c36ef

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