Linear Interpolation
Implement a function to perform linear interpolation between two given values at different times. This task is crucial in frame interpolation, where the goal is to generate intermediate frames between two known frames to create smooth transitions.
The concept of linear interpolation is based on the idea of estimating a value at an intermediate time using the values at the start and end times, and respectively. This is a fundamental technique in motion estimation and computer vision.
Here are the steps to achieve this:
- Define the start and end values, and , and the interpolation factor .
- Use the interpolation factor to compute the weighted average of and .
This technique is widely used in animation and video processing to create smooth transitions between frames.
Example
v0 = 0, v1 = 100, t = 0.5
50.0
- Inputs: is the value at frame 0, is the value at frame 1, and says how far along the way from frame 0 to frame 1 we are (0 = start, 1 = end).
- Weights: the start value gets weight and the end value gets weight . The two weights always add up to , so the result is a weighted average that stays between and .
- Combine: , which rounded to 4 decimal places gives
50.0. - Another view: the same value is : start at and cover a fraction of the gap.
- Notice: the endpoints reproduce the known frames exactly. returns and returns , while would land a quarter of the way, at .
Constraints
- v0 and v1 are values at frames 0 and 1
- t is the interpolation factor (0 to 1)
- Return interpolated value rounded to 4 decimal places