Math and science::Algebra
Sobel operator
The Sobel operator is a first-difference applied after a smoothing. It can be thought of as a solution to problem that the first difference can be too sensitive to noise.
Convolution matrices, horizontal and vertical
\[
S_x \;=\;
\begin{bmatrix}
-1 & 0 & +1 \\
-2 & 0 & +2 \\
-1 & 0 & +1
\end{bmatrix}, \quad
S_y =
\begin{bmatrix}
-1 & -2 & -1 \\
0 & \;\;0 & 0 \\
+1 & +2 & +1
\end{bmatrix}
\]
Factorized as \( \text{derivative} \circ \text{smoothing}(v) \)
\[
S_x = \begin{bmatrix}
1 \\ 2 \\ 1
\end{bmatrix}_{\text{smooth}}
\begin{bmatrix}
-1 & 0 & +1
\end{bmatrix}_{\text{derivative}}
\]
Note that this outer-product creates the convolution kernel, and the order of operations is the opposite of what you would expect from matrix operation order.
The order satisfies:
\[
\bigl(S_y \otimes D_x\bigr) * f
\;=\;
D_x * \bigl(S_y * f\bigr)
\qquad
\text{(smooth in $y$, then differentiate in $x$)}.
\]
A motivating perspective can be to ask: what matrix can we use to shift an image by an arbitrary sub-pixel amount? Peyman Milanfar:

