Refers to a gradient image (compared with adjacent pixels) of a rate of change of the image pixels in both x and y directions, is a two-dimensional vector, a two component composition, changes in the X-axis, Y-axis variations.
Wherein the change in the X-axis is the current pixel to the right (X plus 1) is a pixel value obtained by subtracting the left of the current pixel (X minus 1) pixel value.
Similarly, changes in the Y-axis is the pixel value below the current pixel (Y plus 1) is above the current pixel is subtracted (Y minus 1) pixel value.
Calculated from the two components, forming a two-dimensional vector, to obtain the gradient of the pixel image. Take the arctangent arctan, a gradient angle can be obtained.
This seeking process image gradient can be achieved by a convolution kernel: [- 1,0,1]
absolute values of the gradient image for
image gradient angle
python code
import numpy as np
import scipy.signal as sig
data = np.array([[0, 105, 0], [40, 255, 90], [0, 55, 0]])
G_x = sig.convolve2d(data, np.array([[-1, 0, 1]]), mode='valid')
G_y = sig.convolve2d(data, np.array([[-1], [0], [1]]), mode='valid')