필터 지우기
필터 지우기

Calculate the image gradient

조회 수: 5 (최근 30일)
Donghui  Sun
Donghui Sun 2013년 9월 23일
댓글: Matt J 2017년 3월 1일
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
naser telesi
naser telesi 2017년 3월 1일
if Gx is zero then let Gx = 1 to avoid divide by zero problem
Matt J
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
Matt J 2013년 9월 23일
Use atan2 instead
theta=atan2(Gy,Gx);
  댓글 수: 2
Donghui  Sun
Donghui Sun 2013년 9월 23일
A big thanks.
Image Analyst
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개)

Image Analyst
Image Analyst 2013년 9월 23일
Why do it yourself? Why not just use imgradient()?
  댓글 수: 1
Donghui  Sun
Donghui Sun 2013년 9월 23일
Haha, I just want to try another method. In addition, the gradient direction in imgradient() contains angles in degrees within the range [-180 180]. I need the angle in radians.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by