0
$\begingroup$

I would like to compute the gradient of an image I. I have the following two options :

[Gx, Gy] = gradient(I);
g = sqrt(Gx.^2+Gy.^2);

or

[g,~] = imgradient(I, 'sobel');

My questions are

  1. What is the gradient method used in the first option ?

  2. What are the benefits of using Sobel method to estimate the gradient ?

$\endgroup$
2
  • $\begingroup$ I don't understand question 2 $\endgroup$ – MaximGi Mar 9 '16 at 15:44
  • $\begingroup$ I typo 'benefit'. It means why we use sobel instead of other method to detect edge $\endgroup$ – Jame Mar 9 '16 at 15:50
2
$\begingroup$

Question 1: gradient returns both estimated horizontal $\left(\frac{\partial I}{\partial x}\right)$ and vertical components $\left(\frac{\partial I}{\partial y}\right)$ of the gradient vector, which in your example code are Gx and Gy. To do so, gradient computes for each point $X(i)$ the half difference of $X(i-1)$ and $X(i+1)$, which is the most basic gradient estimation method (it's called the central difference method). Then, computing

g = sqrt(Gx.^2+Gy.^2);  

gives you the gradient magnitude at each point.

imgradient differs since it directly outputs the gradient's magnitude (g) and direction (which you suppressed using ~) at each point. In addition, it computes the gradient using a two-dimensional method applying a sobel kernel to each point and its neighbors. Finally, this function allows you to specify which kernel to use to compute the numerical gradient if you don't want to use the Sobel estimator. You can for example choose to estimate the gradient with the central difference method as in gradient.

Question 2 : Sobel method is just the simplest contour detection method providing good results for a low computation cost. But there are plenty of others, that are used depending on the application I guess. Compared to the central difference method, it achieves better noise rejection using a different kernel with coefficients designed to do so. See as an example the kernel used for horizontal gradient estimation : $$ \begin{matrix} -1 & 0 & 1\\ -2 & 0 & 2\\ -1 & 0 & 1 \end{matrix} $$ The considered point's row is emphasized (factor 2) compared to it's neighbors (factor 1). While the central difference method does not make that difference and weights all points with the same coefficient : $$ \begin{matrix} -1 & 0 & 1\\ -1 & 0 & 1\\ -1 & 0 & 1 \end{matrix} $$

$\endgroup$
4
  • $\begingroup$ I am working in heavy noise image, MR image. I found that Sobel is so good comparison with center difference method. Why it make that benefit? $\endgroup$ – Jame Mar 9 '16 at 16:07
  • $\begingroup$ If 2D central difference, it also 3x3 kernel. Then sobel and central difference method have same performance. Is it right? Because we are working in 2D image $\endgroup$ – Jame Mar 9 '16 at 16:20
  • $\begingroup$ Thanks. Could you provide the reference which said 'better noise rejection by using a bigger kernel'? $\endgroup$ – Jame Mar 9 '16 at 16:25
  • $\begingroup$ I did not find a solid reference for question 2. So I explained as best as I could. $\endgroup$ – MaximGi Mar 9 '16 at 16:37

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.