PIXELBANKv9.1.0
Menu

Light Field Refocusing Shift

Compute the pixel shift for refocusing in a light field.

Light fields enable digital refocusing - changing the focal plane after capture. To focus at depth dd instead of the original d0d_0, we shift each subaperture image by:

shift=(s−s0)⋅d0−ddshift = (s - s_0) \cdot \frac{d_0 - d}{d}

where:

  • ss is the subaperture position
  • s0s_0 is the central subaperture
  • d0d_0 is the original focal distance
  • dd is the target focal distance

Objects at depth dd will be in focus (zero parallax), while objects at other depths are blurred.

Example:

Input:
refocus_shift(2, 0, 10, 5)
Output:
2.0
Reasoning:

Refocusing from d=10 to d=5:

  • shift = (2 - 0) × (10 - 5) / 5
    • = 2 × 5 / 5
    • = 2.0 Subaperture at s=2 shifts by 2 pixels to focus at d=5.

Constraints:

  • s: subaperture position
  • s_center: center subaperture position
  • d_original: original focal distance
  • d_target: target focal distance
  • Return shift in pixels, rounded to 4 decimal places
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.