Task 2 of 5
One equation, two unknowns, is not "nearly enough information". It is a
line of answers. Ix·u + Iy·v + It = 0 is the equation of a
straight line in the (u, v) plane, and every point on it fits this pixel's
evidence equally well. Looking harder at the pixel will not narrow it down; the information
is not there.
What is there is the component of the motion along the gradient. Perpendicular to the gradient the intensity does not change, so sliding that way is invisible. Pick the shortest vector on the line and you get the normal flow:
u = −It · Ix / (Ix² + Iy²)
v = −It · Iy / (Ix² + Iy²)
derivs here comes from a pair you can check by hand. The scene is a sawtooth
ramp climbing 12 levels per step along the (1, 1) diagonal — so every edge in it
runs anti-diagonally — and frame 2 is that scene moved 4 pixels to the right and 0
down. You know the answer. The pixel does not, and cannot.
u, plane 1 is v — and watch it fail to find a motion you know
exactly.output: [64, 64, 2]: plane 0 is u, plane 1 is vderivs[0][y][x], derivs[1][y][x], derivs[2][y][x]-It * Ix / (Ix*Ix + Iy*Iy) for plane 0 and -It * Iy / (Ix*Ix + Iy*Iy) for plane 1(u, v) is where the content went, in pixels per frame — positive u is rightward, positive v is downward. That is the sign that makes Ix·u + Iy·v + It come out zeroNothing is gathered here: thread (x, y) reads exactly three numbers
and returns one. The whole body fits in six lines.
const ix = derivs[0][y][x];
const iy = derivs[1][y][x];
const it = derivs[2][y][x];
const g = ix * ix + iy * iy;
then plane 0 returns (-it * ix) / g and plane 1 returns
(-it * iy) / g. This pair has a gradient at every pixel, so no guard is
needed yet — task 3 is where that stops being true.
NVOF optical-flow engine, OpenCV's calcOpticalFlowFarneback,
the motion-vector passes inside DLSS and FSR. All of them add an assumption on top; none of
them can conjure the missing component out of one pixel.
This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.