Image Processing/ Computer Vision: How is separability of filters implemented? 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&amp;0&amp;1\\-2&amp;0&amp;2\\-1&amp;0&amp;1\end{bmatrix}$

Based on Szeliski



This can be separated as :

$1/2\begin{bmatrix}-1&amp;0&amp;1\end{bmatrix}$ and $1/2\begin{bmatrix}-1\\0\\1\end{bmatrix}$

Consider an image as shown below:

$\begin{bmatrix}1&amp;2&amp;3\\4&amp;5&amp;6\\7&amp;8&amp;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&amp;-0.75&amp;1.125\\-2.5&amp;-1&amp;2.5\\-2.625&amp;-0.75&amp;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&amp;0.5&amp;-1.25\\1.5&amp;0&amp;-1.5\\-1.25&amp;-0.5&amp;1.25\end{bmatrix}$

The two results are different. What's the mistake and how to perform these operations properly?
Szeliski isn't saying what you think they're saying.

The vertical part of the separable filter is:
$$
\mathbf{v_2} = 1/4\begin{bmatrix}1\\2\\1\end{bmatrix}
$$
not
$$
\mathbf{v_1} = 1/2\begin{bmatrix}-1\\0\\1\end{bmatrix}.
$$

You can see this by defining:
$$
\mathbf{h}= 1/2\begin{bmatrix}-1&amp;0&amp;1\end{bmatrix}
$$
and looking at

$$ \mathbf{K_1} = \mathbf{v_1} \mathbf{h} = \begin{bmatrix} 1/4 &amp; 0 &amp; -1/4\\
0 &amp; 0 &amp; 0\\
-1/4 &amp; 0 &amp; 1/4
  \end{bmatrix}$$

and

$$ \mathbf{K_2} = \mathbf{v_2} \mathbf{h}= \begin{bmatrix} -1/8 &amp; 0 &amp; 1/8\\
-1/4 &amp; 0 &amp; 1/4\\
-1/8 &amp; 0 &amp; 1/8
  \end{bmatrix}$$

You can see this effect in the image I included in your question: the vertical edges are highlighted, but the horizontal ones disappear. This is because the $\mathbf{v_2}$ filter is a low-pass filter, not enhancing edges.