How can I compute the direction of gradient at each pixel of an image I ??

2 views (last 30 days)
I need MatLab code to compute gradient direction atan(y/x) for image at each pixel

Answers (4)

Image Analyst
Image Analyst on 8 Jul 2016
Not sure what your difficulty was, but I spent a few minutes and threw together this code to take the tangent of the gradient images. See attached code.

Walter Roberson
Walter Roberson on 29 Jun 2016
atan2() accepts matrix parameters.
I have no idea what your x and y values are going to be, though, unless you are looking at a sequence of images and tracking the fluctuation in each pixel over time.
Have you considered imgradient ? It use a different definition of gradient.

Image Analyst
Image Analyst on 29 Jun 2016
Try imgradient() and/or imgradientxy().

Abdelrahiem  Hashem
Abdelrahiem Hashem on 15 Jul 2016
Edited: Walter Roberson on 15 Jul 2016
I established matrix im0 and try to understand the values in Gmag and Gdir but I can not.!!??
im0=[110 54 36 255 0;255 255 0 0 1;0 0 1 255 120;255 4 87 66 0;0 0 0 0 0]
[Gmag, Gdir] = imgradient(im0)
Please, I need to understand how be computed the first value in Gmag and Gdir (657.8146 and -104.7968) which corresponding to first value 110 in im0.
How can I compute the gradient of an image? - ResearchGate. Available from: https://www.researchgate.net/post/How_can_I_compute_the_gradient_of_an_image#5788522796b7e435a8434272 [accessed Jul 15, 2016].

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!