Gradient Direction in Canny Edge Detection

I am trying to understand the concept of Non-maximum suppression(Canny Edge detection), So I started looking at the matlab code. The part of matlab code to determine the direction of the edge is shown below.

switch direction
    case 1
        idx = find((iy<=0 & ix>-iy)  | (iy>=0 & ix<-iy));
    case 2
        idx = find((ix>0 & -iy>=ix)  | (ix<0 & -iy<=ix));
    case 3
        idx = find((ix<=0 & ix>iy) | (ix>=0 & ix<iy));
    case 4
        idx = find((iy<0 & ix<=iy) | (iy>0 & ix>=iy));
end

Here,

  • ix:input image filtered by derivative of gaussian along x
  • iy:input image filtered by derivative of gaussian along y
  • case 1: 0-45degrees or 181-225degrees
  • case 2: 46-90degrees or 226-270degrees
  • case 3: 91-135degrees or 271-315degrees
  • case 4: 136-180degrees or 316-360degree
  • How are the conditions inside the switch cases corresponds to the cases explained below the code. Could any one please explain this. ?


    At first glance, find((iy<=0 & ix>-iy) | (iy>=0 & ix<-iy)); returns the indices of all pixels where

  • (iy<=0 & ix>-iy) , so
  • the y derivative is less than zero, so the edge is downward, between 90° and 270°
  • the x derivative is greater than zero, so the edge is leftward, between 180° and 360°
  • the magnitude of ix is greater than iy, so the edge is predominantly tilted vertically, not horizontally
  • resulting in an edge between 180° and 225°
  • or (iy>=0 & ix<-iy)) , so
  • the y derivative is greater than zero, so the edge is upward, between 270° and 90°
  • the x derivative is less than zero, so the edge is rightward, between 0° and 180°
  • the magnitude of ix is greater than iy, so the edge is tilted vertically
  • resulting in an edge between 0°and 45°
  • Assuming that the pixels are ordered from up to down and from left to right, and an exactly vertical edge (black on the left, white on the right) is defined as 0°

    The other 3 terms of the switch case are analogous.

    This is not directly related to non-maximum suppression. I assume this is part of a canny edge filter or something similar, in which case the next step would be to find the local maximum in the just determined direction of the edge. This is done by comparing each pixel with its local neighbours in the edge direction, and erasing all but the maximum.

    链接地址: http://www.djcxy.com/p/64034.html

    上一篇: 寻找牌照的边缘

    下一篇: Canny边缘检测中的梯度方向