gradient

menpo.feature.gradient(image, *args, **kwargs)[source]

Calculates the gradient of an input image. The image is assumed to have channel information on the first axis. In the case of multiple channels, it returns the gradient over each axis over each channel as the first axis.

The gradient is computed using second order accurate central differences in the interior and first order accurate one-side (forward or backwards) differences at the boundaries.

Parameters:pixels (Image or subclass or (C, X, Y, ..., Z) ndarray) – Either the image object itself or an array where the first dimension is interpreted as channels. This means an N-dimensional image is represented by an N+1 dimensional array. If the image is 2-dimensional the pixels should be of type float/double (int is not supported).
Returns:gradient (ndarray) – The gradient over each axis over each channel. Therefore, the first axis of the gradient of a 2D, single channel image, will have length 2. The first axis of the gradient of a 2D, 3-channel image, will have length 6, the ordering being I[:, 0, 0] = [R0_y, G0_y, B0_y, R0_x, G0_x, B0_x]. To be clear, all the y-gradients are returned over each channel, then all the x-gradients.