PIXELBANKv9.1.0
Menu

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 (u,v)(u, v) at a pixel location represents the motion of that pixel in the xx and yy 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 ∣v∣=u2+v2|\mathbf{v}| = \sqrt{u^2 + v^2}, where (u,v)(u, v) is the flow vector at that pixel.

  1. Understand the given 2D optical flow field.
  2. Calculate the magnitude at each pixel using the flow vector.
∣v∣=u2+v2 |\mathbf{v}| = \sqrt{u^2 + v^2}

This technique is widely used in traffic monitoring applications to measure velocity.

Example:

Input:
flow = [[(3, 4), (0, 0)],
       [(1, 0), (0, 1)]]
Output:
[[5.0, 0.0], [1.0, 1.0]]
Reasoning:

Computing magnitude at each pixel:

  • (0,0): |v| = √(3² + 4²) = √25 = 5.0
  • (0,1): |v| = √(0² + 0²) = 0.0
  • (1,0): |v| = √(1² + 0²) = 1.0
  • (1,1): |v| = √(0² + 1²) = 1.0

Result: [[5.0, 0.0], [1.0, 1.0]]

Constraints:

  • flow is a 2D array of (u, v) tuples
  • Return magnitude array rounded to 2 decimal places
🔒

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.
Flow Field Magnitude - Easy | PixelBank