sobel-y --> [ 1   2   1]
                             [ 0   0   0]
                             [-1  -2  -1]

                sobel-x -->  [1  0 -1]
                             [2  0 -2]
                             [1  0 -1] 

Is it possible to combine two Sobel kernels (x-direction, and y-direction) into one and then convolve that with an image?

The idea is that, I already have an Convolution function written. I would be able to reuse it in that way.


I tried Fat32's suggestion of applying X and Y kernels sequentially.


Expected Output:

Present Output:

Looks like my filter isn't producing the correct output.

  • $\begingroup$ I think all you need to do is convolve the two kernels. $\endgroup$ – MBaz Sep 3 '18 at 23:07
  • $\begingroup$ So you have a convolution function, you will call it twice, with those two directional kernels.... (@MBaz convolving them would not be a good idea, for these are edge detectors) $\endgroup$ – Fat32 Sep 3 '18 at 23:32
  • $\begingroup$ @MBaz, your suggestion isn't working. $\endgroup$ – user36563 Sep 4 '18 at 0:33
  • $\begingroup$ I do not suggest sequential filtering..? you will filter the original image two times in parallel one with hx and the other with hy producing two different images, then their squares are added. I assume you want a Sobel edge detector... $\endgroup$ – Fat32 Sep 4 '18 at 0:42
  • $\begingroup$ @Fat32 My idea was that, if $H_x$ and $H_y$ are the OP's two matrices, and $I$ is the image, then one could calculate $(H_x \ast H_y) \ast I$ since convolution is associative. Of course, if you do non-linear operations in between, then this wouldn't work, as you point out in your answer. $\endgroup$ – MBaz Sep 4 '18 at 12:58

A Sobel edge detector compares an approximation of the image gradient $|\nabla f_c(x,y)|$ to a threshold to decide if a pixel is an edge or not. A proper threshold must be determined and computed so that the comparison produces useful results. The approximation is given by the following:

$$|\nabla f_c(x,y)| \longrightarrow \sqrt{ (f \star h_x)^2 + (f \star h_y)^2 }$$

where $f = f[n_1,n_2]$ is the discrete-time image sequence, and $h_x = h_x[n_1,n_2]$ and $h_y = h_y[n_1,n_2]$ are the two directional Sobel kernels respectively.

As can be seen the Sobel operator is nonlinear in the filters $h_x$ and $h_y$, and a single kernel cannot be obtained, which would replace those two directional kernels.

| improve this answer | |
  • $\begingroup$ Question edited. $\endgroup$ – user36563 Sep 4 '18 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy