v9.1.1
Menu

Disparity-Based View Warping

mediumPROView InterpolationIBRCV: Image-Based Rendering

Warp an image using a disparity map for view synthesis.

To synthesize a novel view at position tt between two cameras, we shift pixels based on their disparity:

usrc=utgt−t⋅d(u,v)u_{src} = u_{tgt} - t \cdot d(u, v)

where:

  • utgtu_{tgt} is the target pixel x-coordinate
  • d(u,v)d(u, v) is the disparity at that pixel
  • tt is the interpolation factor (0 = left view, 1 = right view)
  • usrcu_{src} is where to sample from the source image

This "backward warping" approach samples the source image at computed coordinates, avoiding holes in the output.

Example

Input
warp_by_disparity([[1, 2, 3, 4]], [[0, 1, 1, 0]], 1)
Output
[[1, 1, 2, 4]]
Reasoning
  • Inputs: image is a 1×41 \times 4 strip of intensities [1,2,3,4][1, 2, 3, 4]; disparity gives each target pixel's horizontal shift, [0,1,1,0][0, 1, 1, 0], so the two middle pixels belong to a nearer surface; t =1= 1 means we synthesise the full right-hand view.
  • Math: every output pixel utgtu_{tgt} asks where it came from, usrc=utgt−t⋅du_{src} = u_{tgt} - t \cdot d. Only the column moves; the row stays the same.
  • Column 0: 0−1⋅0=00 - 1 \cdot 0 = 0, value 11. Column 1: 1−1⋅1=01 - 1 \cdot 1 = 0, value 11. Column 2: 2−1⋅1=12 - 1 \cdot 1 = 1, value 22. Column 3: 3−1⋅0=33 - 1 \cdot 0 = 3, value 44.
  • A fractional usrcu_{src} goes to the nearest column, and anything left of column 0 or right of column w−1w-1 is clamped to the edge.
  • Output: [[1, 1, 2, 4]], same size as the input. Notice that intensity 33 vanishes and 11 appears twice: backward warping never leaves a hole, but it can duplicate or drop source pixels where disparity changes.

Constraints

  • image: 2D source image
  • disparity: 2D disparity map (same dimensions)
  • t: interpolation factor
  • Use nearest-neighbor sampling with boundary clamping
  • Return warped image

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.