odak.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 |
np.complex64 |
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' |
initial_phase |
np.complex64 |
Phase to be added to the initial value. |
None |
Returns:
Type | Description |
---|---|
np.complex |
Calculated complex hologram. |
Source code in odak/wave/classical.py
def gerchberg_saxton(field, n_iterations, distance, dx, wavelength, slm_range=6.28, propagation_type='IR Fresnel', initial_phase=None):
"""
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 : np.complex64
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).
initial_phase : np.complex64
Phase to be added to the initial value.
Returns
-------
hologram : np.complex
Calculated complex hologram.
reconstruction : np.complex
Calculated reconstruction using calculated hologram.
"""
k = wavenumber(wavelength)
target = calculate_amplitude(field)
hologram = generate_complex_field(np.ones(field.shape), 0)
hologram = zero_pad(hologram)
if type(initial_phase) == type(None):
hologram = add_random_phase(hologram)
else:
initial_phase = zero_pad(initial_phase)
hologram = add_phase(hologram, initial_phase)
center = [int(hologram.shape[0]/2.), int(hologram.shape[1]/2.)]
orig_shape = [int(field.shape[0]/2.), int(field.shape[1]/2.)]
for i in tqdm(range(n_iterations), leave=False):
reconstruction = propagate_beam(
hologram, k, distance, dx, wavelength, propagation_type)
new_target = calculate_amplitude(reconstruction)
new_target[
center[0]-orig_shape[0]:center[0]+orig_shape[0],
center[1]-orig_shape[1]:center[1]+orig_shape[1]
] = target
reconstruction = generate_complex_field(
new_target, calculate_phase(reconstruction))
hologram = propagate_beam(
reconstruction, k, -distance, dx, wavelength, propagation_type)
hologram = generate_complex_field(1, calculate_phase(hologram))
hologram = hologram[
center[0]-orig_shape[0]:center[0]+orig_shape[0],
center[1]-orig_shape[1]:center[1]+orig_shape[1],
]
hologram = zero_pad(hologram)
reconstruction = propagate_beam(
hologram, k, distance, dx, wavelength, propagation_type)
hologram = hologram[
center[0]-orig_shape[0]:center[0]+orig_shape[0],
center[1]-orig_shape[1]:center[1]+orig_shape[1]
]
reconstruction = reconstruction[
center[0]-orig_shape[0]:center[0]+orig_shape[0],
center[1]-orig_shape[1]:center[1]+orig_shape[1]
]
return hologram, reconstruction