Skip to content

Hello DefocusLens

Script: 0_hello_defocuslens.py

A lightweight thin-lens defocus (circle-of-confusion) model for depth-of-field and bokeh simulation — no ray tracing or wave optics required.

What it demonstrates

  • Constructing a DefocusLens from focal length, F-number, and focus distance.
  • Computing the defocus PSF for an out-of-focus point.
  • Rendering a flat scene with depth-dependent blur.

Run

python 0_hello_defocuslens.py

Key code

from deeplens import DefocusLens

lens = DefocusLens(foclen=50.0, fnum=1.8, foc_dist=-1000.0)

# Circle of confusion / depth of field across a range of depths
coc = lens.coc(depths)
dof = lens.dof(depths)

# Defocus PSF and rendered image
psf = lens.psf(points=[0.0, 0.2, -1500.0])
img_render = lens.render(img, depth=-1500.0)

Results

Defocus PSF Rendered (with blur)
PSF Render

See also