Mathematically, the operator uses two 3×3 kernels which are
convolved with the original image to calculate approximations of the derivatives - one for horizontal changes, and one for vertical. If we define \mathbf{A} as the source image, and \mathbf{G_x} and \mathbf{G_y} are two images which at each point contain the horizontal and vertical derivative approximations, the latter are computed as: : \mathbf{G_y} = \begin{bmatrix} +1 &+1 &+1 \\ 0 &0 &0 \\ -1 &-1 &-1 \end{bmatrix} * \mathbf{A} \quad \mbox{and} \quad \mathbf{G_x} = \begin{bmatrix} +1 & 0 & -1 \\ +1 & 0 & -1 \\ +1 & 0 & -1 \end{bmatrix} * \mathbf{A} where * here denotes the 2-dimensional
convolution operation. Since the Prewitt kernels can be decomposed as the products of an averaging and a differentiation kernel, they compute the gradient with smoothing. Therefore, it is a
separable filter. For example, \mathbf{G_x} can be written as : \begin{bmatrix} +1 & 0 & -1 \\ +1 & 0 & -1 \\ +1 & 0 & -1 \end{bmatrix} = \begin{bmatrix} 1\\ 1\\ 1 \end{bmatrix} \begin{bmatrix} +1 & 0 & -1 \end{bmatrix} The
x-coordinate is defined here as increasing in the "left"-direction, and the
y-coordinate is defined as increasing in the "up"-direction. At each point in the image, the resulting gradient approximations can be combined to give the gradient magnitude, using: :\mathbf{G} = \sqrt{ {\mathbf{G}_x}^2 + {\mathbf{G}_y}^2 } Using this information, we can also calculate the gradient's direction: :\mathbf{\Theta} = \operatorname{atan2}\left({ \mathbf{G}_y , \mathbf{G}_x }\right) where, for example,
Θ is 0 for a vertical edge which is darker on the right side. ==Example==