问题
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?
回答1:
Non-max suppression is a way to eliminate points that do not lie in important edges. In your first case if the gradient is close to zero degrees at a given point, that means the edge is to the north or to the south, and that point will be considered to be on the edge if the magnitude of this point is greater than both magnitudes of the points to its left and right (as in your example). In your second case you are checking for gradient at 45 degrees, so the edge is at 135 degrees, and so you keep the point if it is greater than the points along the gradient direction, i.e. (-1, -1) and (1, 1). Rotating the coordinate system doesn't affect this.
回答2:
Here's a python implementation of Non Maxima Suppression used in Canny Edge Detection process.
They concentrate on North and South, North-East and South-West, East and West, and South-East and North-West. Then decide which values to keep.
Hope it helps someone who needs NMS for finding better edge.
回答3:
Might be late for the original question, but the following link might help anyone struggling to understand non-max suppression.
Java Demo of non-max suppression
来源:https://stackoverflow.com/questions/13659517/non-max-suppression