We've learned that you can get the gradient direction with atan(dy/dx)
which is the direction orthogonal to the edge.
Now we had a homework where we were supposed to discretize this direction into four classes (x- and y-direction and both diagonals) and then check both pixel neighbors in the best matching direction for non-max suppression.
I didn't fully get the solution though. Obviously we had four cases:
abs(angle) < pi/8
, so the gradient (roughly) points in x-direction, thus we checkimg(i, j-1)
andimg(i, j+1)
(assuming the image origin is in the top left)angle > pi/8 && angle <= 3*pi/8
, so the gradient points to the top right. Now I thought we need to checkimg(i-1, j+1)
andimg(i+1, j-1)
but instead we checkimg(i-1, j-1)
andimg(i+1, j+1)
which seems like the orthogonal diagonal.
The other two cases are equivalent. I tried to change this but then the edges really look weird so this seems correct but I don't understand why.
Can someone explain this to me?