v9.1.1
Menu

Bilinear Light Field Interpolation

mediumPROLight FieldsLight FieldCV: Image-Based Rendering

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, with corners (⌊s⌋,⌊t⌋)(\lfloor s \rfloor, \lfloor t \rfloor) through (⌊s⌋+1,⌊t⌋+1)(\lfloor s \rfloor + 1, \lfloor t \rfloor + 1)
  • A corner missing from samples counts as color 00 (this happens when the query lies on the last grid line, where that corner's weight is zero anyway)

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
  • samples stores the colour captured by each camera on the integer grid: (0,0)→100(0,0) \to 100, (1,0)→200(1,0) \to 200, (0,1)→150(0,1) \to 150, (1,1)→250(1,1) \to 250.
  • The enclosing cell's lower corner is (⌊0.5⌋,⌊0.5⌋)=(0,0)(\lfloor 0.5 \rfloor, \lfloor 0.5 \rfloor) = (0, 0), so fs=0.5f_s = 0.5 and ft=0.5f_t = 0.5.
  • Each corner's weight is the area of the rectangle opposite it: (1−fs)(1−ft)(1-f_s)(1-f_t), fs(1−ft)f_s(1-f_t), (1−fs)ft(1-f_s)f_t and fsftf_s f_t all equal 0.250.25 here. The four weights always sum to 11.
  • Blending in ss first gives the same answer: bottom edge 0.5⋅100+0.5⋅200=1500.5 \cdot 100 + 0.5 \cdot 200 = 150, top edge 0.5⋅150+0.5⋅250=2000.5 \cdot 150 + 0.5 \cdot 250 = 200, then in tt: 0.5⋅150+0.5⋅200=1750.5 \cdot 150 + 0.5 \cdot 200 = 175.
  • The output 175.0 is the plain average of the four cameras, since the query is equidistant from all of them.
  • Notice that at an integer query such as (1,1)(1, 1), fs=ft=0f_s = f_t = 0, so one camera takes all the weight and you get 250; the absent far corners like (2,1)(2, 1) count as 00 with zero weight.

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

Learn this in

More from CV: Image-Based Rendering

PRO

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

Sign in to run your code against the test cases.