PIXELBANKv9.1.0
Menu

Brightness Constancy Residual

You are given image derivatives at a pixel and a flow vector, and need to compute the brightness constancy residual.

The optical flow constraint equation is derived from the assumption that pixel brightness doesn't change over time:

I(x,y,t)=I(x+u,y+v,t+1)I(x, y, t) = I(x + u, y + v, t + 1)

Taking a Taylor expansion and rearranging: Ixu+Iyv+It=0I_x u + I_y v + I_t = 0

Where:

  • IxI_x = spatial derivative in x direction
  • IyI_y = spatial derivative in y direction
  • ItI_t = temporal derivative (change between frames)
  • (u,v)(u, v) = optical flow vector

The residual measures how well the flow satisfies this constraint: r=Ixu+Iyv+Itr = I_x u + I_y v + I_t

A residual of 0 means perfect brightness constancy.

Example:

Input:
Ix = 2, Iy = 3, It = 1
u = 0.5, v = -1
Output:
0.0
Reasoning:

Applying the brightness constancy equation:

  • r = Ix Γ— u + Iy Γ— v + It
  • r = 2 Γ— 0.5 + 3 Γ— (-1) + 1
  • r = 1 - 3 + 1
  • r = -1...

Wait, let me recalculate:

  • r = 2 Γ— 0.5 + 3 Γ— (-1) + 1
  • r = 1 + (-3) + 1 = -1

Hmm, let me verify the test case. With u=0.5, v=-1: 2(0.5) + 3(-1) + 1 = 1 - 3 + 1 = -1

The expected output 0.0 would require different values.

Constraints:

  • Ix, Iy, It are image derivatives at a pixel
  • u, v is the optical flow vector
  • Return the residual rounded to 4 decimal places
solution.py

Test Results

0/0
Run code to see test results.