computer_vision.horn_schunck¶
The Horn-Schunck method estimates the optical flow for every single pixel of a sequence of images. It works by assuming brightness constancy between two consecutive frames and smoothness in the optical flow.
Useful resources: Wikipedia: https://en.wikipedia.org/wiki/Horn%E2%80%93Schunck_method Paper: http://image.diku.dk/imagecanon/material/HornSchunckOptical_Flow.pdf
Functions¶
|
This function performs the Horn-Schunck algorithm and returns the estimated |
|
Warps the pixels of an image into a new image using the horizontal and vertical |
Module Contents¶
- computer_vision.horn_schunck.horn_schunck(image0: numpy.ndarray, image1: numpy.ndarray, num_iter: SupportsIndex, alpha: float | None = None) tuple[numpy.ndarray, numpy.ndarray] ¶
This function performs the Horn-Schunck algorithm and returns the estimated optical flow. It is assumed that the input images are grayscale and normalized to be in [0, 1].
- Parameters:
image0: First image of the sequence image1: Second image of the sequence alpha: Regularization constant num_iter: Number of iterations performed
Returns: estimated horizontal & vertical flow
>>> np.round(horn_schunck(np.array([[0, 0, 2], [0, 0, 2]]), np.array([[0, 2, 0], [0, 2, 0]]), alpha=0.1, num_iter=110)). astype(np.int32) array([[[ 0, -1, -1], [ 0, -1, -1]], [[ 0, 0, 0], [ 0, 0, 0]]], dtype=int32)
- computer_vision.horn_schunck.warp(image: numpy.ndarray, horizontal_flow: numpy.ndarray, vertical_flow: numpy.ndarray) numpy.ndarray ¶
Warps the pixels of an image into a new image using the horizontal and vertical flows. Pixels that are warped from an invalid location are set to 0.
- Parameters:
image: Grayscale image horizontal_flow: Horizontal flow vertical_flow: Vertical flow
Returns: Warped image
>>> warp(np.array([[0, 1, 2], [0, 3, 0], [2, 2, 2]]), np.array([[0, 1, -1], [-1, 0, 0], [1, 1, 1]]), np.array([[0, 0, 0], [0, 1, 0], [0, 0, 1]])) array([[0, 0, 0], [3, 1, 0], [0, 2, 3]])