odak.learn.wave.gerchberg_saxton¶
Definition to compute a hologram using an iterative method called Gerchberg-Saxton phase retrieval algorithm. For more on the method, see: Gerchberg, Ralph W. "A practical algorithm for the determination of phase from image and diffraction plane pictures." Optik 35 (1972): 237-246.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
torch.cfloat |
Complex field (MxN). |
required |
distance |
float |
Propagation distance. |
required |
dx |
float |
Size of one single pixel in the field grid (in meters). |
required |
wavelength |
float |
Wavelength of the electric field. |
required |
slm_range |
float |
Typically this is equal to two pi. See odak.wave.adjust_phase_only_slm_range() for more. |
6.28 |
propagation_type |
str |
Type of the propagation (IR Fresnel, TR Fresnel, Fraunhofer). |
'IR Fresnel' |
Returns:
Type | Description |
---|---|
torch.cfloat |
Calculated complex hologram. |
Source code in odak/learn/wave/classical.py
def gerchberg_saxton(field, n_iterations, distance, dx, wavelength, slm_range=6.28, propagation_type='IR Fresnel'):
"""
Definition to compute a hologram using an iterative method called Gerchberg-Saxton phase retrieval algorithm. For more on the method, see: Gerchberg, Ralph W. "A practical algorithm for the determination of phase from image and diffraction plane pictures." Optik 35 (1972): 237-246.
Parameters
----------
field : torch.cfloat
Complex field (MxN).
distance : float
Propagation distance.
dx : float
Size of one single pixel in the field grid (in meters).
wavelength : float
Wavelength of the electric field.
slm_range : float
Typically this is equal to two pi. See odak.wave.adjust_phase_only_slm_range() for more.
propagation_type : str
Type of the propagation (IR Fresnel, TR Fresnel, Fraunhofer).
Returns
-------
hologram : torch.cfloat
Calculated complex hologram.
reconstruction : torch.cfloat
Calculated reconstruction using calculated hologram.
"""
k = wavenumber(wavelength)
reconstruction = field
for i in range(n_iterations):
hologram = propagate_beam(
reconstruction, k, -distance, dx, wavelength, propagation_type)
hologram, _ = produce_phase_only_slm_pattern(hologram, slm_range)
reconstruction = propagate_beam(
hologram, k, distance, dx, wavelength, propagation_type)
reconstruction = set_amplitude(reconstruction, field)
reconstruction = propagate_beam(
hologram, k, distance, dx, wavelength, propagation_type)
return hologram, reconstruction
Notes¶
To optimize a phase-only hologram using Gerchberg-Saxton algorithm, please follow and observe the below example:
import torch
from odak.learn.wave import gerchberg_saxton
from odak import np
wavelength = 0.000000532
dx = 0.0000064
distance = 0.2
target_field = torch.zeros((500,500),dtype=torch.complex64)
target_field[0::50,:] += 1
iteration_number = 3
hologram,reconstructed = gerchberg_saxton(
target_field,
iteration_number,
distance,
dx,
wavelength,
np.pi*2,
'TR Fresnel'
)