1
$\begingroup$

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

 sbl=fspecial('Sobel');
 sbl_red=imfilter(Image(:,:,1));

Method 2

 [magred,dirred]=imgradient(Image(:,:,1),'Sobel')

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.

$\endgroup$
  • $\begingroup$ Build your own filters. That is the only way to know what you are doing $\endgroup$ – mathreadler Jun 9 '18 at 6:17
1
$\begingroup$

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.

$\endgroup$

Your Answer

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

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