I am trying to convince myself that a separable 2D filter can be implemented via two 1D filters. So, I took the example of following Sobel filter:
$1/8\begin{bmatrix}-1&0&1\\-2&0&2\\-1&0&1\end{bmatrix}$
Based on Szeliski
This can be separated as :
$1/2\begin{bmatrix}-1&0&1\end{bmatrix}$ and $1/2\begin{bmatrix}-1\\0\\1\end{bmatrix}$
Consider an image as shown below:
$\begin{bmatrix}1&2&3\\4&5&6\\7&8&9\end{bmatrix}$
Let us first perform a normal 2D convolution which involves:
1) flipping the kernel horizontally and vertically (i.e first interchange first and last rows, then interchange first and last columns).
2) applying the flipped kernel on the image (the border is assumed to be zero padded).
3) Normalizing values by dividing them by 8.
This yields the output:
$\begin{bmatrix}-1.125&-0.75&1.125\\-2.5&-1&2.5\\-2.625&-0.75&2.625\end{bmatrix}$
Now we can try applying 1D filters:
1) The 1D filter represented by the row vector is flipped (columns are interchanged).
2) The flipped filter is applied to the entire image.
3) The 1D filter represented by the column vector is flipped (rows are interchanged).
4) The flipped filter is applied to the result from first 1D convolution.
5) The values are normalized by dividing them by 4.
This yields the output:
$\begin{bmatrix}1.25&0.5&-1.25\\1.5&0&-1.5\\-1.25&-0.5&1.25\end{bmatrix}$
The two results are different. What's the mistake and how to perform these operations properly?