odak.learn.wave
angular_spectrum(field, k, distance, dx, wavelength, zero_padding=False, aperture=1.0)
¶
A definition to calculate convolution with Angular Spectrum method for beam propagation.
Parameters:
-
field
–Complex field [m x n].
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
zero_padding
–Zero pad in Fourier domain.
-
aperture
–Fourier domain aperture (e.g., pinhole in a typical holographic display). The default is one, but an aperture could be as large as input field [m x n].
Returns:
-
result
(complex
) –Final complex field (MxN).
Source code in odak/learn/wave/classical.py
band_limited_angular_spectrum(field, k, distance, dx, wavelength, zero_padding=False, aperture=1.0)
¶
A definition to calculate bandlimited angular spectrum based beam propagation. For more
Matsushima, Kyoji, and Tomoyoshi Shimobaba. "Band-limited angular spectrum method for numerical simulation of free-space propagation in far and near fields." Optics express 17.22 (2009): 19662-19673
.
Parameters:
-
field
–A complex field. The expected size is [m x n].
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
zero_padding
–Zero pad in Fourier domain.
-
aperture
–Fourier domain aperture (e.g., pinhole in a typical holographic display). The default is one, but an aperture could be as large as input field [m x n].
Returns:
-
result
(complex
) –Final complex field [m x n].
Source code in odak/learn/wave/classical.py
custom(field, kernel, zero_padding=False, aperture=1.0)
¶
A definition to calculate convolution based Fresnel approximation for beam propagation.
Parameters:
-
field
–Complex field [m x n].
-
kernel
–Custom complex kernel for beam propagation.
-
zero_padding
–Zero pad in Fourier domain.
-
aperture
–Fourier domain aperture (e.g., pinhole in a typical holographic display). The default is one, but an aperture could be as large as input field [m x n].
Returns:
-
result
(complex
) –Final complex field (MxN).
Source code in odak/learn/wave/classical.py
fraunhofer(field, k, distance, dx, wavelength)
¶
A definition to calculate light transport usin Fraunhofer approximation.
Parameters:
-
field
–Complex field (MxN).
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
Returns:
-
result
(complex
) –Final complex field (MxN).
Source code in odak/learn/wave/classical.py
gerchberg_saxton(field, n_iterations, distance, dx, wavelength, slm_range=6.28, propagation_type='Transfer Function 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
–Complex field (MxN).
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
slm_range
–Typically this is equal to two pi. See odak.wave.adjust_phase_only_slm_range() for more.
-
propagation_type
(str
, default:'Transfer Function Fresnel'
) –Type of the propagation (see odak.learn.wave.propagate_beam).
Returns:
-
hologram
(cfloat
) –Calculated complex hologram.
-
reconstruction
(cfloat
) –Calculated reconstruction using calculated hologram.
Source code in odak/learn/wave/classical.py
get_angular_spectrum_kernel(nu, nv, dx=8e-06, wavelength=5.15e-07, distance=0.0, device=torch.device('cpu'))
¶
Helper function for odak.learn.wave.angular_spectrum.
Parameters:
-
nu
–Resolution at X axis in pixels.
-
nv
–Resolution at Y axis in pixels.
-
dx
–Pixel pitch in meters.
-
wavelength
–Wavelength in meters.
-
distance
–Distance in meters.
-
device
–Device, for more see torch.device().
Returns:
-
H
(float
) –Complex kernel in Fourier domain.
Source code in odak/learn/wave/classical.py
get_band_limited_angular_spectrum_kernel(nu, nv, dx=8e-06, wavelength=5.15e-07, distance=0.0, device=torch.device('cpu'))
¶
Helper function for odak.learn.wave.band_limited_angular_spectrum.
Parameters:
-
nu
–Resolution at X axis in pixels.
-
nv
–Resolution at Y axis in pixels.
-
dx
–Pixel pitch in meters.
-
wavelength
–Wavelength in meters.
-
distance
–Distance in meters.
-
device
–Device, for more see torch.device().
Returns:
-
H
(complex64
) –Complex kernel in Fourier domain.
Source code in odak/learn/wave/classical.py
get_impulse_response_fresnel_kernel(nu, nv, dx=8e-06, wavelength=5.15e-07, distance=0.0, device=torch.device('cpu'), scale=1, aperture_samples=[20, 20, 5, 5])
¶
Helper function for odak.learn.wave.impulse_response_fresnel.
Parameters:
-
nu
–Resolution at X axis in pixels.
-
nv
–Resolution at Y axis in pixels.
-
dx
–Pixel pitch in meters.
-
wavelength
–Wavelength in meters.
-
distance
–Distance in meters.
-
device
–Device, for more see torch.device().
-
scale
–Scale with respect to nu and nv (e.g., scale = 2 leads to 2 x nu and 2 x nv resolution for H).
-
aperture_samples
–Number of samples to represent a rectangular pixel. First two is for XY of hologram plane pixels, and second two is for image plane pixels.
Returns:
-
H
(complex64
) –Complex kernel in Fourier domain.
Source code in odak/learn/wave/classical.py
get_incoherent_angular_spectrum_kernel(nu, nv, dx=8e-06, wavelength=5.15e-07, distance=0.0, device=torch.device('cpu'))
¶
Helper function for odak.learn.wave.angular_spectrum.
Parameters:
-
nu
–Resolution at X axis in pixels.
-
nv
–Resolution at Y axis in pixels.
-
dx
–Pixel pitch in meters.
-
wavelength
–Wavelength in meters.
-
distance
–Distance in meters.
-
device
–Device, for more see torch.device().
Returns:
-
H
(float
) –Complex kernel in Fourier domain.
Source code in odak/learn/wave/classical.py
get_light_kernels(wavelengths, distances, pixel_pitches, resolution=[1080, 1920], resolution_factor=1, samples=[50, 50, 5, 5], propagation_type='Bandlimited Angular Spectrum', kernel_type='spatial', device=torch.device('cpu'))
¶
Utility function to request a tensor filled with light transport kernels according to the given optical configurations.
Parameters:
-
wavelengths
–A list of wavelengths.
-
distances
–A list of propagation distances.
-
pixel_pitches
–A list of pixel_pitches.
-
resolution
–Resolution of the light transport kernel.
-
resolution_factor
–If `Impulse Response Fresnel` propagation is used, this resolution factor could be set larger than one leading to higher resolution light transport kernels than the provided native `resolution`. For more, see odak.learn.wave.get_impulse_response_kernel().
-
samples
–If `Impulse Response Fresnel` propagation is used, these sample counts will be used to calculate the light transport kernel. For more, see odak.learn.wave.get_impulse_response_kernel().
-
propagation_type
–Propagation type. For more, see odak.learn.wave.propagate_beam().
-
kernel_type
–If set to `spatial`, light transport kernels will be provided in space. But if set to `fourier`, these kernels will be provided in the Fourier domain.
-
device
–Device used for computation (i.e., cpu, cuda).
Returns:
-
light_kernels_amplitude
(tensor
) –Amplitudes of the light kernels generated [w x d x p x m x n].
-
light_kernels_phase
(tensor
) –Phases of the light kernels generated [w x d x p x m x n].
-
light_kernels_complex
(tensor
) –Complex light kernels generated [w x d x p x m x n].
-
light_parameters
(tensor
) –Parameters of each pixel in light_kernels* [w x d x p x m x n x 5]. Last dimension contains, wavelengths, distances, pixel pitches, X and Y locations in order.
Source code in odak/learn/wave/classical.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
|
get_point_wise_impulse_response_fresnel_kernel(aperture_points, aperture_field, target_points, resolution, resolution_factor=1, wavelength=5.15e-07, distance=0.0, randomization=False, device=torch.device('cpu'))
¶
This function is a freeform point spread function calculation routine for an aperture defined with a complex field, aperture_field
, and locations in space, aperture_points
.
The point spread function is calculated over provided points, target_points
.
The final result is reshaped to follow the provided resolution
.
Parameters:
-
aperture_points
–Points representing an aperture in Euler space (XYZ) [m x 3].
-
aperture_field
–Complex field for each point provided by `aperture_points` [1 x m].
-
target_points
–Target points where the propagated field will be calculated [n x 1].
-
resolution
–Final resolution that the propagated field will be reshaped [X x Y].
-
resolution_factor
–Scale with respect to `resolution` (e.g., scale = 2 leads to `2 x resolution` for the final complex field.
-
wavelength
–Wavelength in meters.
-
randomization
–If set `True`, this will help generate a noisy response roughly approximating a real life case, where imperfections occur.
-
distance
–Distance in meters.
Returns:
-
h
(float
) –Complex field in spatial domain.
Source code in odak/learn/wave/classical.py
get_propagation_kernel(nu, nv, dx=8e-06, wavelength=5.15e-07, distance=0.0, device=torch.device('cpu'), propagation_type='Bandlimited Angular Spectrum', scale=1, samples=[20, 20, 5, 5])
¶
Get propagation kernel for the propagation type.
Parameters:
-
nu
–Resolution at X axis in pixels.
-
nv
–Resolution at Y axis in pixels.
-
dx
–Pixel pitch in meters.
-
wavelength
–Wavelength in meters.
-
distance
–Distance in meters.
-
device
–Device, for more see torch.device().
-
propagation_type
–Propagation type. The options are `Angular Spectrum`, `Bandlimited Angular Spectrum` and `Transfer Function Fresnel`.
-
scale
–Scale factor for scaled beam propagation.
-
samples
–When using `Impulse Response Fresnel` propagation, these sample counts along X and Y will be used to represent a rectangular aperture. First two is for a hologram pixel and second two is for an image plane pixel.
Returns:
-
kernel
(tensor
) –Complex kernel for the given propagation type.
Source code in odak/learn/wave/classical.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
get_seperable_impulse_response_fresnel_kernel(nu, nv, dx=3.74e-06, wavelength=5.15e-07, distance=0.0, scale=1, aperture_samples=[50, 50, 5, 5], device=torch.device('cpu'))
¶
Returns impulse response fresnel kernel in separable form.
Parameters:
-
nu
–Resolution at X axis in pixels.
-
nv
–Resolution at Y axis in pixels.
-
dx
–Pixel pitch in meters.
-
wavelength
–Wavelength in meters.
-
distance
–Distance in meters.
-
device
–Device, for more see torch.device().
-
scale
–Scale with respect to nu and nv (e.g., scale = 2 leads to 2 x nu and 2 x nv resolution for H).
-
aperture_samples
–Number of samples to represent a rectangular pixel. First two is for XY of hologram plane pixels, and second two is for image plane pixels.
Returns:
-
H
(complex64
) –Complex kernel in Fourier domain.
-
h
(complex64
) –Complex kernel in spatial domain.
-
h_x
(complex64
) –1D complex kernel in spatial domain along X axis.
-
h_y
(complex64
) –1D complex kernel in spatial domain along Y axis.
Source code in odak/learn/wave/classical.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
|
get_transfer_function_fresnel_kernel(nu, nv, dx=8e-06, wavelength=5.15e-07, distance=0.0, device=torch.device('cpu'))
¶
Helper function for odak.learn.wave.transfer_function_fresnel.
Parameters:
-
nu
–Resolution at X axis in pixels.
-
nv
–Resolution at Y axis in pixels.
-
dx
–Pixel pitch in meters.
-
wavelength
–Wavelength in meters.
-
distance
–Distance in meters.
-
device
–Device, for more see torch.device().
Returns:
-
H
(complex64
) –Complex kernel in Fourier domain.
Source code in odak/learn/wave/classical.py
impulse_response_fresnel(field, k, distance, dx, wavelength, zero_padding=False, aperture=1.0, scale=1, samples=[20, 20, 5, 5])
¶
A definition to calculate convolution based Fresnel approximation for beam propagation.
Parameters:
-
field
–Complex field (MxN).
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
zero_padding
–Zero pad in Fourier domain.
-
aperture
–Fourier domain aperture (e.g., pinhole in a typical holographic display). The default is one, but an aperture could be as large as input field [m x n].
-
scale
–Resolution factor to scale generated kernel.
-
samples
–When using `Impulse Response Fresnel` propagation, these sample counts along X and Y will be used to represent a rectangular aperture. First two is for hologram plane pixel and the last two is for image plane pixel.
Returns:
-
result
(complex
) –Final complex field (MxN).
Source code in odak/learn/wave/classical.py
incoherent_angular_spectrum(field, k, distance, dx, wavelength, zero_padding=False, aperture=1.0)
¶
A definition to calculate incoherent beam propagation with Angular Spectrum method.
Parameters:
-
field
–Complex field [m x n].
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
zero_padding
–Zero pad in Fourier domain.
-
aperture
–Fourier domain aperture (e.g., pinhole in a typical holographic display). The default is one, but an aperture could be as large as input field [m x n].
Returns:
-
result
(complex
) –Final complex field [m x n].
Source code in odak/learn/wave/classical.py
point_wise(target, wavelength, distance, dx, device, lens_size=401)
¶
Naive point-wise hologram calculation method. For more information, refer to Maimone, Andrew, Andreas Georgiou, and Joel S. Kollin. "Holographic near-eye displays for virtual and augmented reality." ACM Transactions on Graphics (TOG) 36.4 (2017): 1-16.
Parameters:
-
target
–float input target to be converted into a hologram (Target should be in range of 0 and 1).
-
wavelength
–Wavelength of the electric field.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
device
–Device type (cuda or cpu)`.
-
lens_size
–Size of lens for masking sub holograms(in pixels).
Returns:
-
hologram
(cfloat
) –Calculated complex hologram.
Source code in odak/learn/wave/classical.py
propagate_beam(field, k, distance, dx, wavelength, propagation_type='Bandlimited Angular Spectrum', kernel=None, zero_padding=[True, False, True], aperture=1.0, scale=1, samples=[20, 20, 5, 5])
¶
Definitions for various beam propagation methods mostly in accordence with "Computational Fourier Optics" by David Vuelz.
Parameters:
-
field
–Complex field [m x n].
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
propagation_type
(str
, default:'Bandlimited Angular Spectrum'
) –Type of the propagation. The options are Impulse Response Fresnel, Transfer Function Fresnel, Angular Spectrum, Bandlimited Angular Spectrum, Fraunhofer.
-
kernel
–Custom complex kernel.
-
zero_padding
–Zero padding the input field if the first item in the list set True. Zero padding in the Fourier domain if the second item in the list set to True. Cropping the result with half resolution if the third item in the list is set to true. Note that in Fraunhofer propagation, setting the second item True or False will have no effect.
-
aperture
–Aperture at Fourier domain default:[2m x 2n], otherwise depends on `zero_padding`. If provided as a floating point 1, there will be no aperture in Fourier domain.
-
scale
–Resolution factor to scale generated kernel.
-
samples
–When using `Impulse Response Fresnel` propagation, these sample counts along X and Y will be used to represent a rectangular aperture. First two is for a hologram pixel and second two is for an image plane pixel.
Returns:
-
result
(complex
) –Final complex field [m x n].
Source code in odak/learn/wave/classical.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
seperable_impulse_response_fresnel(field, k, distance, dx, wavelength, zero_padding=False, aperture=1.0, scale=1, samples=[20, 20, 5, 5])
¶
A definition to calculate convolution based Fresnel approximation for beam propagation for a rectangular aperture using the seperable property.
Parameters:
-
field
–Complex field (MxN).
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
zero_padding
–Zero pad in Fourier domain.
-
aperture
–Fourier domain aperture (e.g., pinhole in a typical holographic display). The default is one, but an aperture could be as large as input field [m x n].
-
scale
–Resolution factor to scale generated kernel.
-
samples
–When using `Impulse Response Fresnel` propagation, these sample counts along X and Y will be used to represent a rectangular aperture. First two is for hologram plane pixel and the last two is for image plane pixel.
Returns:
-
result
(complex
) –Final complex field (MxN).
Source code in odak/learn/wave/classical.py
shift_w_double_phase(phase, depth_shift, pixel_pitch, wavelength, propagation_type='Transfer Function Fresnel', kernel_length=4, sigma=0.5, amplitude=None)
¶
Shift a phase-only hologram by propagating the complex hologram and double phase principle. Coded following in here and Shi, L., Li, B., Kim, C., Kellnhofer, P., & Matusik, W. (2021). Towards real-time photorealistic 3D holography with deep neural networks. Nature, 591(7849), 234-239.
Parameters:
-
phase
–Phase value of a phase-only hologram.
-
depth_shift
–Distance in meters.
-
pixel_pitch
–Pixel pitch size in meters.
-
wavelength
–Wavelength of light.
-
propagation_type
(str
, default:'Transfer Function Fresnel'
) –Beam propagation type. For more see odak.learn.wave.propagate_beam().
-
kernel_length
–Kernel length for the Gaussian blur kernel.
-
sigma
–Standard deviation for the Gaussian blur kernel.
-
amplitude
–Amplitude value of a complex hologram.
Source code in odak/learn/wave/classical.py
1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 |
|
stochastic_gradient_descent(target, wavelength, distance, pixel_pitch, propagation_type='Bandlimited Angular Spectrum', n_iteration=100, loss_function=None, learning_rate=0.1)
¶
Definition to generate phase and reconstruction from target image via stochastic gradient descent.
Parameters:
-
target
–Target field amplitude [m x n]. Keep the target values between zero and one.
-
wavelength
–Set if the converted array requires gradient.
-
distance
–Hologram plane distance wrt SLM plane.
-
pixel_pitch
–SLM pixel pitch in meters.
-
propagation_type
–Type of the propagation (see odak.learn.wave.propagate_beam()).
-
n_iteration
–Number of iteration.
-
loss_function
–If none it is set to be l2 loss.
-
learning_rate
–Learning rate.
Returns:
-
hologram
(Tensor
) –Phase only hologram as torch array
-
reconstruction_intensity
(Tensor
) –Reconstruction as torch array
Source code in odak/learn/wave/classical.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 |
|
transfer_function_fresnel(field, k, distance, dx, wavelength, zero_padding=False, aperture=1.0)
¶
A definition to calculate convolution based Fresnel approximation for beam propagation.
Parameters:
-
field
–Complex field (MxN).
-
k
–Wave number of a wave, see odak.wave.wavenumber for more.
-
distance
–Propagation distance.
-
dx
–Size of one single pixel in the field grid (in meters).
-
wavelength
–Wavelength of the electric field.
-
zero_padding
–Zero pad in Fourier domain.
-
aperture
–Fourier domain aperture (e.g., pinhole in a typical holographic display). The default is one, but an aperture could be as large as input field [m x n].
Returns:
-
result
(complex
) –Final complex field (MxN).
Source code in odak/learn/wave/classical.py
blazed_grating(nx, ny, levels=2, axis='x')
¶
A defininition to generate a blazed grating (also known as ramp grating). For more consult de Blas, Mario García, et al. "High resolution 2D beam steerer made from cascaded 1D liquid crystal phase gratings." Scientific Reports 12.1 (2022): 5145 and Igasaki, Yasunori, et al. "High efficiency electrically-addressable phase-only spatial light modulator." optical review 6 (1999): 339-344.
Parameters:
-
nx
–Size of the output along X.
-
ny
–Size of the output along Y.
-
levels
–Number of pixels.
-
axis
–Axis of glazed grating. It could be `x` or `y`.
Source code in odak/learn/wave/lens.py
linear_grating(nx, ny, every=2, add=None, axis='x')
¶
A definition to generate a linear grating. This could also be interpreted as two levels blazed grating. For more on blazed gratings see odak.learn.wave.blazed_grating() function.
Parameters:
-
nx
–Size of the output along X.
-
ny
–Size of the output along Y.
-
every
–Add the add value at every given number.
-
add
–Angle to be added.
-
axis
–Axis eiter X,Y or both.
Returns:
-
field
(tensor
) –Linear grating term.
Source code in odak/learn/wave/lens.py
prism_grating(nx, ny, k, angle, dx=0.001, axis='x', phase_offset=0.0)
¶
A definition to generate 2D phase function that represents a prism. See Goodman's Introduction to Fourier Optics book or Engström, David, et al. "Improved beam steering accuracy of a single beam with a 1D phase-only spatial light modulator." Optics express 16.22 (2008): 18275-18287. for more.
Parameters:
-
nx
–Size of the output along X.
-
ny
–Size of the output along Y.
-
k
–See odak.wave.wavenumber for more.
-
angle
–Tilt angle of the prism in degrees.
-
dx
–Pixel pitch.
-
axis
–Axis of the prism.
-
phase_offset
(float
, default:0.0
) –Phase offset in angles. Default is zero.
Returns:
-
prism
(tensor
) –Generated phase function for a prism.
Source code in odak/learn/wave/lens.py
quadratic_phase_function(nx, ny, k, focal=0.4, dx=0.001, offset=[0, 0])
¶
A definition to generate 2D quadratic phase function, which is typically use to represent lenses.
Parameters:
-
nx
–Size of the output along X.
-
ny
–Size of the output along Y.
-
k
–See odak.wave.wavenumber for more.
-
focal
–Focal length of the quadratic phase function.
-
dx
–Pixel pitch.
-
offset
–Deviation from the center along X and Y axes.
Returns:
-
function
(tensor
) –Generated quadratic phase function.
Source code in odak/learn/wave/lens.py
multiplane_loss
¶
Loss function for computing loss in multiplanar images. Unlike, previous methods, this loss function accounts for defocused parts of an image.
Source code in odak/learn/wave/loss.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
|
__call__(image, target, plane_id=None)
¶
Calculates the multiplane loss against a given target.
Parameters:
-
image
–Image to compare with a target [3 x m x n].
-
target
–Target image for comparison [3 x m x n].
-
plane_id
–Number of the plane under test.
Returns:
-
loss
(tensor
) –Computed loss.
Source code in odak/learn/wave/loss.py
__init__(target_image, target_depth, blur_ratio=0.25, target_blur_size=10, number_of_planes=4, weights=[1.0, 2.1, 0.6], multiplier=1.0, scheme='defocus', reduction='mean', device=torch.device('cpu'))
¶
Parameters:
-
target_image
–Color target image [3 x m x n].
-
target_depth
–Monochrome target depth, same resolution as target_image.
-
target_blur_size
–Maximum target blur size.
-
blur_ratio
–Blur ratio, a value between zero and one.
-
number_of_planes
–Number of planes.
-
weights
–Weights of the loss function.
-
multiplier
–Multiplier to multipy with targets.
-
scheme
–The type of the loss, `naive` without defocus or `defocus` with defocus.
-
reduction
–Reduction can either be 'mean', 'none' or 'sum'. For more see: https://pytorch.org/docs/stable/generated/torch.nn.MSELoss.html#torch.nn.MSELoss
-
device
–Device to be used (e.g., cuda, cpu, opencl).
Source code in odak/learn/wave/loss.py
add_defocus_blur()
¶
Internal function for adding defocus blur to the multiplane targets. Users can query the results with get_targets() within the same class.
Source code in odak/learn/wave/loss.py
get_targets()
¶
Returns:
-
targets
(tensor
) –Returns a copy of the targets.
-
target_depth
(tensor
) –Returns a copy of the normalized quantized depth map.
Source code in odak/learn/wave/loss.py
set_targets()
¶
Internal function for slicing the depth into planes without considering defocus. Users can query the results with get_targets() within the same class.
Source code in odak/learn/wave/loss.py
perceptual_multiplane_loss
¶
Perceptual loss function for computing loss in multiplanar images. Unlike, previous methods, this loss function accounts for defocused parts of an image.
Source code in odak/learn/wave/loss.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
|
__call__(image, target, plane_id=None)
¶
Calculates the multiplane loss against a given target.
Parameters:
-
image
–Image to compare with a target [3 x m x n].
-
target
–Target image for comparison [3 x m x n].
-
plane_id
–Number of the plane under test.
Returns:
-
loss
(tensor
) –Computed loss.
Source code in odak/learn/wave/loss.py
__init__(target_image, target_depth, blur_ratio=0.25, target_blur_size=10, number_of_planes=4, multiplier=1.0, scheme='defocus', base_loss_weights={'base_l2_loss': 1.0, 'loss_l2_mask': 1.0, 'loss_l2_cor': 1.0, 'base_l1_loss': 1.0, 'loss_l1_mask': 1.0, 'loss_l1_cor': 1.0}, additional_loss_weights={'cvvdp': 1.0}, reduction='mean', return_components=False, device=torch.device('cpu'))
¶
Parameters:
-
target_image
–Color target image [3 x m x n].
-
target_depth
–Monochrome target depth, same resolution as target_image.
-
target_blur_size
–Maximum target blur size.
-
blur_ratio
–Blur ratio, a value between zero and one.
-
number_of_planes
–Number of planes.
-
multiplier
–Multiplier to multipy with targets.
-
scheme
–The type of the loss, `naive` without defocus or `defocus` with defocus.
-
base_loss_weights
–Weights of the base loss functions. Default is {'base_l2_loss': 1., 'loss_l2_mask': 1., 'loss_l2_cor': 1., 'base_l1_loss': 1., 'loss_l1_mask': 1., 'loss_l1_cor': 1.}.
-
additional_loss_weights
(dict
, default:{'cvvdp': 1.0}
) –Additional loss terms and their weights (e.g., {'cvvdp': 1.}). Supported loss terms are 'cvvdp', 'fvvdp', 'lpips', 'psnr', 'ssim', 'msssim'.
-
reduction
–Reduction can either be 'mean', 'none' or 'sum'. For more see: https://pytorch.org/docs/stable/generated/torch.nn.MSELoss.html#torch.nn.MSELoss
-
return_components
–If True (False by default), returns the components of the loss as a dict.
-
device
–Device to be used (e.g., cuda, cpu, opencl).
Source code in odak/learn/wave/loss.py
add_defocus_blur()
¶
Internal function for adding defocus blur to the multiplane targets. Users can query the results with get_targets() within the same class.
Source code in odak/learn/wave/loss.py
get_targets()
¶
Returns:
-
targets
(tensor
) –Returns a copy of the targets.
-
target_depth
(tensor
) –Returns a copy of the normalized quantized depth map.
Source code in odak/learn/wave/loss.py
set_targets()
¶
Internal function for slicing the depth into planes without considering defocus. Users can query the results with get_targets() within the same class.
Source code in odak/learn/wave/loss.py
phase_gradient
¶
Bases: Module
The class 'phase_gradient' provides a regularization function to measure the variation(Gradient or Laplace) of the phase of the complex amplitude.
This implements a convolution of the phase with a kernel.
The kernel is a simple 3 by 3 Laplacian kernel here, but you can also try other edge detection methods.
Source code in odak/learn/wave/loss.py
__init__(kernel=None, loss=nn.MSELoss(), device=torch.device('cpu'))
¶
Parameters:
-
kernel
–Convolution filter kernel, 3 by 3 Laplacian kernel by default.
-
loss
–loss function, L2 Loss by default.
Source code in odak/learn/wave/loss.py
forward(phase)
¶
Calculates the phase gradient Loss.
Parameters:
-
phase
–Phase of the complex amplitude.
Returns:
-
loss_value
(tensor
) –The computed loss.
Source code in odak/learn/wave/loss.py
functional_conv2d(phase)
¶
Calculates the gradient of the phase.
Parameters:
-
phase
–Phase of the complex amplitude.
Returns:
-
edge_detect
(tensor
) –The computed phase gradient.
Source code in odak/learn/wave/loss.py
speckle_contrast
¶
Bases: Module
The class 'speckle_contrast' provides a regularization function to measure the speckle contrast of the intensity of the complex amplitude using C=sigma/mean. Where C is the speckle contrast, mean and sigma are mean and standard deviation of the intensity.
We refer to the following paper:
Kim et al.(2020). Light source optimization for partially coherent holographic displays with consideration of speckle contrast, resolution, and depth of field. Scientific Reports. 10. 18832. 10.1038/s41598-020-75947-0.
Source code in odak/learn/wave/loss.py
__init__(kernel_size=11, step_size=(1, 1), loss=nn.MSELoss(), device=torch.device('cpu'))
¶
Parameters:
-
kernel_size
–Convolution filter kernel size, 11 by 11 average kernel by default.
-
step_size
–Convolution stride in height and width direction.
-
loss
–loss function, L2 Loss by default.
Source code in odak/learn/wave/loss.py
forward(intensity)
¶
Calculates the speckle contrast Loss.
Parameters:
-
intensity
–intensity of the complex amplitude.
Returns:
-
loss_value
(tensor
) –The computed loss.
Source code in odak/learn/wave/loss.py
functional_conv2d(intensity)
¶
Calculates the speckle contrast of the intensity.
Parameters:
-
intensity
–Intensity of the complex field.
Returns:
-
Speckle_C
(tensor
) –The computed speckle contrast.