PIXELBANKv9.1.0
Menu

Disparity-Based View Warping

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:

Warping with t=1 (full disparity shift):

  • Pixel 0: src = 0 - 1Γ—0 = 0 β†’ sample image[0] = 1
  • Pixel 1: src = 1 - 1Γ—1 = 0 β†’ sample image[0] = 1
  • Pixel 2: src = 2 - 1Γ—1 = 1 β†’ sample image[1] = 2
  • Pixel 3: src = 3 - 1Γ—0 = 3 β†’ sample image[3] = 4 Result: [1, 1, 2, 4]

Constraints:

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

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.
Disparity-Based View Warping - Medium | PixelBank