Bidirectional Frame Blending
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 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:
This technique is widely used in video processing and computer vision applications.
Example
frame0 = [[0, 0], [0, 0]] frame1 = [[100, 100], [100, 100]] t = 0.5
[[50, 50], [50, 50]]
- Inputs:
frame0andframe1are two grayscale frames of the same size.frame0is completely black (every intensity is 0) andframe1is a uniform gray of intensity 100.t = 0.5asks for the frame halfway between them. - Weights: the first frame gets weight and the second gets . The two weights always add up to 1, so the result stays inside the range spanned by the two inputs.
- One pixel: . 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 frame of integers. - Notice: slides the result between the two frames. At you get
frame0back unchanged, at you getframe1, and 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