PIXELBANKv9.1.0
Menu

Rolling Shutter Correction

Implement a rolling shutter correction algorithm to rectify distorted video frames using gyroscope data. This task involves compensating for the skew caused by camera rotation during the rolling shutter capture process, where each row is captured at a slightly different time.

The rolling shutter effect is a consequence of the way images are captured in most cameras, where the sensor reads out the pixel values row by row, rather than all at once. When the camera rotates during this process, it results in a skewed image, which can be modeled using affine transformations. The gyroscope data provides the per-row rotation, which can be used to apply an inverse transformation to correct the distortion.

To achieve this, the following steps are involved:

  1. Understand the rotation matrix and how it relates to the gyroscope data.
  2. Apply the inverse rotation to each row of the image.
  3. Interpolate the pixel values to handle the resulting non-integer coordinates.
(x′y′)=(cos⁡(θ)−sin⁡(θ)sin⁡(θ)cos⁡(θ))(xy)\begin{pmatrix} x' \\ y' \end{pmatrix} = \begin{pmatrix} \cos(\theta) & -\sin(\theta) \\ \sin(\theta) & \cos(\theta) \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix}

This technique is widely used in video stabilization applications.

Example:

Input:
Frame and rotation per row
Output:
Corrected frame
Reasoning:

Apply inverse rotation to each row

Constraints:

  • Input parameters: image (2D numpy array, grayscale or RGB), rotation_per_row (1D numpy array of angles in radians)
  • Valid ranges: Pixel values in [0, 255], rotation angles in [-π, π]
  • Output format: Return the corrected frame as a 2D numpy array (same shape and type as input image)
  • Special conditions: Assume the input image has a height of at least 2 rows, and the rotation_per_row array has the same length as the number of rows in the image
🔒

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.
Rolling Shutter Correction - Hard | PixelBank