# brainbox.video

Functions for analyzing video frame data

Functions

 `frame_diff` Outputs pythagorean distance between two frames `frame_diffs` Return the difference between frames. `motion_energy` Returns a min-max normalized vector of motion energy between frames.
frame_diff(frame1, frame2)[source]

Outputs pythagorean distance between two frames

Parameters:
• frame1 – A numpy array of pixels with a shape of either (m, n, 3) or (m, n)

• frame2 – A numpy array of pixels with a shape of either (m, n, 3) or (m, n)

Returns:

An array with a shape equal to the input frames

frame_diffs(frames, diff=1)[source]

Return the difference between frames. May also take difference between more than 1 frames. Values are normalized between 0-255.

Parameters:
• frames – Array or list of frames, where each frame is either (y, x) or (y, x, 3).

• diff – Take difference between frames N and frames N + diff.

Returns:

uint8 array with shape (n-diff, y, x).

motion_energy(frames, diff=2, kernel=None, normalize=True)[source]

Returns a min-max normalized vector of motion energy between frames.

Parameters:
• frames – A list of ndarray of frames.

• diff – Take difference between frames N and frames N + diff.

• kernel – An optional Gaussian smoothing to apply with a given kernel size.

• normalize – If True, motion energy is min-max normalized

Return dfdf_:

A vector of length n frames - diff, normalized between 0 and 1.

Return stDev:

The standard deviation between the frames (not normalized).

Example 1 - Calculate normalized difference between consecutive frames

df, std = motion_energy(frames, diff=1)

Example 2 - Calculate smoothed difference between every 2nd frame

df, _ = motion_energy(frames, kernel=(9, 9))