MATLAB Answers

Can we rotate sobel operator and still get the same results for gradient image

14 views (last 30 days)
Navdeep Sony
Navdeep Sony on 6 Feb 2016
Answered: Anand on 9 Feb 2016
I have a 5*5 image and I applied imgradient() on it and got the directions(just focussing on directions). I also tried to calculate the directions for the same image on paper using the following sobel operators.
gx=[-1 0 1; -2 0 2; -1 0 1] gy=[-1 -2 -1; 0 0 0; 1 2 1]
I found theta using
Gdir = atan2(-gy,gx)*180/pi %Note: gy is negative as y moves from top to bottom
and got same answers as were obtained using imgradient().
But when I used
gx=[1 0 -1; 2 0 -2; 1 0 -1] gy=[1 2 1; 0 0 0; -1 -2 -1]
I got different answers. Why?
Can't we rotate sobel operator and still get the same results. Does MATLAB uses a fixed set of sobel operators to find gradient and never uses the rotated version? What is the problem. Please explain.

  0 Comments

Sign in to comment.

Answers (1)

Anand
Anand on 9 Feb 2016
The imgradient function uses the following kernels for the 'sobel':
hx = -fspecial('sobel')'
hx =
-1 0 1
-2 0 2
-1 0 1
hy = -fspecial('sobel')
hy =
-1 -2 -1
0 0 0
1 2 1
You get different results with the rotated kernels because the Sobel kernel is not symmetric.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by