I am using the Sobel filter for an RGB image. I have found two different ways to do that and the results look a little different. What is the difference between these two methods?

Method 1


Method 2


Is there an advantage over one of the two methods? I am trying to find a structure of the image that is parallel to the x axis.

  • $\begingroup$ Build your own filters. That is the only way to know what you are doing $\endgroup$ Jun 9, 2018 at 6:17

1 Answer 1


Well, if you go through the documentation of fspecial() you'd see it returns the following filter:

h = fspecial('sobel') returns a 3-by-3 filter h that emphasizes horizontal edges using the smoothing effect by approximating a vertical gradient. To emphasize vertical edges, transpose the filter h'.

[ 1  2  1 
  0  0  0 
 -1 -2 -1 ]

Namely in the way you applied it above you only got the vertical element of the gradient.

While imgradient() returns the image of the magnitude of the Gradient (Which has Vertical and Horizontal elements) and its direction.


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.