How do I interpret the orientation of the gradient when using imgradient in MATLAB?
<p>I am finding the gradient of an image. For now I am simply using a 5 x 5 image. I am more interested in finding the direction of the gradient but I am not getting the results manually on paper as I get them using MATLAB function <code>imgradient</code>. Please refer to the following images to know more about the input images and the Sobel filter that is used here to find the gradient of an image. One of the 3 x 3 sobel operator used here is the one that I get using the function                </p>

<pre><code>f1 = fspecial('sobel');
</code></pre>

<p>and the other one is obtained by just transposing the <code>f1</code>.</p>

<p>Please note that I am trying to find the direction of only one pixel here that is rounded by red color.  Here in the first two cases my result matches with that i obtain using <code>imgradient</code> function but in the third case <code>imgradient</code> gives -135 degree whereas I am getting it to be -45. Please help me find the error.</p>

<p><img src="https://i.stack.imgur.com/kdgUm.jpg" alt="Case one and case two"></p>

<p><img src="https://i.stack.imgur.com/LvCBk.jpg" alt="Case three (Mismatch in results)"></p>

<p>Also please explain how to interpret the following gradient directions as shown in the follwing image.</p>

<p><a href="https://i.stack.imgur.com/AwuTB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AwuTB.jpg" alt="enter image description here"></a></p>