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:


Based on Szeliski

Figure 3.14 from 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:


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:


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:


The two results are different. What's the mistake and how to perform these operations properly?


1 Answer 1


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&0&1\end{bmatrix} $$ and looking at

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


$$ \mathbf{K_2} = \mathbf{v_2} \mathbf{h}= \begin{bmatrix} -1/8 & 0 & 1/8\\ -1/4 & 0 & 1/4\\ -1/8 & 0 & 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.

  • 1
    $\begingroup$ Thank you for pointing out the error. However, shouldn't the normalization factor for $v_2$ be 4 instead of 2? $\endgroup$
    – skr
    Dec 12, 2018 at 18:08
  • $\begingroup$ @skr_robo Correct! I'll edit to fix. $\endgroup$
    – Peter K.
    Dec 12, 2018 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.