brainbox.video¶
Functions for analyzing video frame data
Functions
Outputs pythagorean distance between two frames :param frame1: A numpy array of pixels with a shape of either (m, n, 3) or (m, n) :param frame2: A numpy array of pixels with a shape of either (m, n, 3) or (m, n) :return: An array with a shape equal to the input frames 

Return the difference between frames. 

Returns a minmax normalized vector of motion energy between frames. 

frame_diff
(frame1, frame2)[source]¶ Outputs pythagorean distance between two frames :param frame1: A numpy array of pixels with a shape of either (m, n, 3) or (m, n) :param frame2: A numpy array of pixels with a shape of either (m, n, 3) or (m, n) :return: 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 0255. :param frames: Array or list of frames, where each frame is either (y, x) or (y, x, 3). :param diff: Take difference between frames N and frames N + diff. :return: uint8 array with shape (ndiff, y, x).

motion_energy
(frames, diff=2, kernel=None, normalize=True)[source]¶ Returns a minmax normalized vector of motion energy between frames. :param frames: A list of ndarray of frames. :param diff: Take difference between frames N and frames N + diff. :param kernel: An optional Gaussian smoothing to apply with a given kernel size. :param normalize: If True, motion energy is minmax normalized :return df_: 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))