PIXELBANKv9.1.0
Menu

Bilinear Light Field Interpolation

Interpolate color from a light field using bilinear interpolation.

Given a query position (s,t)(s, t) between captured camera positions, we interpolate from the four nearest cameras using bilinear weights:

C=(1βˆ’fs)(1βˆ’ft)C00+fs(1βˆ’ft)C10+(1βˆ’fs)ftC01+fsftC11C = (1-f_s)(1-f_t) C_{00} + f_s(1-f_t) C_{10} + (1-f_s)f_t C_{01} + f_s f_t C_{11}

where:

  • fs=sβˆ’βŒŠsβŒ‹f_s = s - \lfloor s \rfloor is the fractional part in s
  • ft=tβˆ’βŒŠtβŒ‹f_t = t - \lfloor t \rfloor is the fractional part in t
  • CijC_{ij} are the colors at the four corner cameras

This enables smooth transitions between camera positions.

Example:

Input:
interpolate_lightfield({(0,0): 100, (1,0): 200, (0,1): 150, (1,1): 250}, 0.5, 0.5)
Output:
175.0
Reasoning:

Bilinear interpolation at (0.5, 0.5):

  • fs = 0.5, ft = 0.5
  • C = (1-0.5)(1-0.5)Γ—100 + 0.5Γ—(1-0.5)Γ—200 + (1-0.5)Γ—0.5Γ—150 + 0.5Γ—0.5Γ—250
    • = 0.25Γ—100 + 0.25Γ—200 + 0.25Γ—150 + 0.25Γ—250
    • = 25 + 50 + 37.5 + 62.5 = 175

Constraints:

  • samples: dict mapping (s, t) integer coordinates to color values
  • query_s, query_t: floating-point query position
  • Return interpolated color, 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.
Bilinear Light Field Interpolation - Medium | PixelBank