Skip to content

Hello DiffractiveLens

Script: 0_hello_diffraclens.py

A pure wave-optics lens built from a diffractive phase plate. The complex wavefront is propagated to the sensor with the band-limited Angular Spectrum Method (ASM). Runs in float64 for phase accuracy.

What it demonstrates

  • Loading a DiffractiveLens from JSON (here a Fresnel phase plate).
  • Computing the PSF for an object at infinity, at finite depth, and off-axis.
  • Wave-optics image rendering through the diffractive lens.

Run

python 0_hello_diffraclens.py

Key code

import torch
from deeplens import DiffractiveLens

lens = DiffractiveLens(filename="./datasets/lenses/diffraclens/fresnel.json")  # float64

psf_inf = lens.psf(points=[0.0, 0.0, float("-inf")])   # collimated, on-axis
psf_near = lens.psf(points=[0.0, 0.0, -200.0])         # finite depth
psf_off = lens.psf(points=[0.0, 0.7, float("-inf")])   # off-axis
img_render = lens.render(img, depth=-200.0)

Results

PSF (object at ∞) PSF (near) PSF (off-axis)
inf near off

Rendered image

Render

Note

The Fresnel plate is sampled at 2 µm so the quadratic phase is well-sampled (ps < λ·f/D) and forms a clean, diffraction-limited focus. Coarser pixel pitches undersample the phase and produce ghost-lattice PSFs; see DiffractiveLens design for the sampling rule.

See also