v9.1.1
Menu

Bidirectional Frame Blending

mediumPROFrame InterpolationInterpolationCV: Motion Estimation

Implement a frame interpolation technique to generate an intermediate frame between two given frames. This task is crucial in motion estimation and video processing as it enables the creation of smooth motion sequences.

The concept of frame interpolation is based on linear interpolation, where each pixel in the intermediate frame is calculated as a weighted average of the corresponding pixels in the input frames. The interpolation factor tt controls the blending process, ranging from 0 (first frame) to 1 (second frame).

Each pixel of the intermediate frame is computed independently, and the blended value is rounded to the nearest integer:

It(x,y)=(1−t)⋅I0(x,y)+t⋅I1(x,y)I_t(x, y) = (1 - t) \cdot I_0(x, y) + t \cdot I_1(x, y)

This technique is widely used in video processing and computer vision applications.

Example

Input
frame0 = [[0, 0], [0, 0]]
frame1 = [[100, 100], [100, 100]]
t = 0.5
Output
[[50, 50], [50, 50]]
Reasoning
  • Inputs: frame0 and frame1 are two 2×22 \times 2 grayscale frames of the same size. frame0 is completely black (every intensity is 0) and frame1 is a uniform gray of intensity 100. t = 0.5 asks for the frame halfway between them.
  • Weights: the first frame gets weight 1−t=0.51 - t = 0.5 and the second gets t=0.5t = 0.5. The two weights always add up to 1, so the result stays inside the range spanned by the two inputs.
  • One pixel: I0.5(x,y)=0.5⋅0+0.5⋅100=0+50=50I_{0.5}(x, y) = 0.5 \cdot 0 + 0.5 \cdot 100 = 0 + 50 = 50. Rounding to the nearest integer leaves it at 50.
  • Every pixel: both frames are uniform, so all four positions give the same value, and the output is [[50, 50], [50, 50]], a 2×22 \times 2 frame of integers.
  • Notice: tt slides the result between the two frames. At t=0t = 0 you get frame0 back unchanged, at t=1t = 1 you get frame1, and t=0.25t = 0.25 here would give 25 everywhere.

Constraints

  • frame0 and frame1 are 2D grayscale images of same size
  • t is interpolation factor (0 to 1)
  • Return blended frame with values rounded to nearest integer

Learn this in

More from CV: Motion Estimation

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.