Asked by Syakira Akmal
on 11 Apr 2017

Hi, i have this kind of formula

dy=(X,Y+1)-(X,Y-1)

dx=(X+1,Y)-(X-1,Y)

(X,Y)=(dx^2+dy^2)^1/2

and i want to convert into coding form.Can anyone help me? and I just get confuse whether the formula need to be to a second derivation or just power of 2 the value?

Answer by Image Analyst
on 11 Apr 2017

Accepted Answer

Use imgradient():

[Gx, Gy] = imgradientxy(I); % Gx is what you call dx and Gy is what you call dy.

[Gmag, Gdir] = imgradient(Gx, Gy); % Gmag is what you call alpha.

Munshida P
on 25 Aug 2019 at 3:59

AG measures the gradient magnitude of an image and takes thevariation of each of the adjacent pixels into account. AG is given asfollows:

AG= 1/((H−1) (W−1))xyG (x, y)√2

where H × W is the size of the image and G(•)is the gradient vectorof the image.

How can i calculate this ...average gradient from

[Gx, Gy] = imgradientxy(I); % Gx is what you call dx and Gy is what you call dy.

[Gmag, Gdir] = imgradient(Gx, Gy); % Gmag is what you call alpha.

Please help me.

Image Analyst
on 25 Aug 2019 at 17:29

Each point has exactly one gradient, with both a magnitude and a direction, which you can decompose into two orthogonal vectors along the x and y direction if you want or need to.

What is the average you desire being taken over? Gmag is the gradient magnitude at each point, like I said, so if you want the "average" gradient then you must want it averaged over several points. So . . . which points? All points in a square window centered at the point? If so, what is the window size? All points in a circular window centered around the point? Again, what size?

Possibly more important than that is WHY you want the average gradient. So, why do you want the average instead of the actual gradient?

PPO POT
on 11 Sep 2019 at 23:15

Please give me your original paper that give the equation of AG= 1/((H−1) (W−1))xyG (x, y)√2 to me.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Syakira Akmal (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/334913-convert-formula-into-coding-form#comment_445062

## Rik (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/334913-convert-formula-into-coding-form#comment_445064

Sign in to comment.