Calculate the image gradient
7 次查看(过去 30 天)
显示 更早的评论
I use the function imgradientxy to get the Gx and Gy firstly. Then obtain the direction of the gradient.
some codes like:
% code
b = zeros(100);
b(1:4:end,:) = 1;
[Gx, Gy] = imgradientxy(b);
theta = atan(Gy./Gx);
The image only has some horizontal lines. So The Gx is all zeros and the theta have a lot NAN. What should I do to get the gradient for this image and for other?
2 个评论
Matt J
2017-3-1
if Gx is zero then let Gx = 1 to avoid divide by zero problem
But theta will be wrong...
采纳的回答
Matt J
2013-9-23
Use atan2 instead
theta=atan2(Gy,Gx);
2 个评论
Image Analyst
2013-9-23
Like I said, imgradient() already gives that to you as Gdir - see the help. No need to do it yourself with atan2.
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!