Flow Field Magnitude
Implement a function to compute the magnitude of a given 2D optical flow field at each pixel, which represents the speed of motion. The optical flow field is a 2D vector field where each vector at a pixel location represents the motion of that pixel in the and directions.
The concept of optical flow is crucial in Computer Vision as it helps in understanding the motion of objects in a scene. The magnitude of flow at each pixel is calculated using the formula , where is the flow vector at that pixel.
- Understand the given 2D optical flow field.
- Calculate the magnitude at each pixel using the flow vector.
This technique is widely used in traffic monitoring applications to measure velocity.
Example
flow = [[(3, 4), (0, 0)],
[(1, 0), (0, 1)]][[5.0, 0.0], [1.0, 1.0]]
- Input:
flowis a grid of pixels. Each pixel holds a flow vector : how far that pixel moved horizontally () and vertically () between frames. - Top-left : the speed is the length of the vector, . This is the classic 3-4-5 right triangle.
- Top-right : the pixel did not move, so .
- Bottom row and : one unit right and one unit down. Both give , so the direction differs but the speed is identical.
- Output:
[[5.0, 0.0], [1.0, 1.0]], a grid with the same layout as the input, but each pixel now holds one non-negative number instead of a pair. Values are rounded to 2 decimal places, so a vector like would give . - Notice that magnitude throws away direction: , and all map to .
Constraints
- flow is a 2D array of (u, v) tuples
- Return magnitude array rounded to 2 decimal places