Canny edge detector: Difference between revisions

Content added Content deleted
Line 698: Line 698:
unique =: 3 : 'y*i.$y'
unique =: 3 : 'y*i.$y'
connect =: 3 : 'attach^:_ unique y'
connect =: 3 : 'attach^:_ unique y'
octant =: 3 : '4|(>.(_0.5+((4%(o. 1))*(12&o. y))))' NB. eighth of circle


canny =: 3 : 0
canny =: 3 : 0
Line 715: Line 716:
NB. Step 3 - edge detection
NB. Step 3 - edge detection


NB. find the octant (eighth of circle) in which the gradient lies
octant =: 3 : '4|(>.(_0.5+((4%(o. 1))*(12&o. y))))'
NB. test pattern <(i:6)(4 : 'octant (x j. y)')"0/(i:6)
NB. test pattern <(i:6)(4 : 'octant (x j. y)')"0/(i:6)


Line 724: Line 723:
NB. is this gradient the greatest of immmediate colinear neighbore?
NB. is this gradient the greatest of immmediate colinear neighbore?
greatestOf =: 4 : '(x greaterThan y) *. ((-x) greaterThan y)'
greatestOf =: 4 : '(x greaterThan y) *. ((-x) greaterThan y)'

NB. find the octant (eighth of circle) in which the gradient lies
NB. relative address of neighbor relevant to grad direction
krnl0 =: _1 0
krnl1 =: _1 _1
krnl2 =: 0 _1
krnl3 =: 1 _1
og =: octant image2
og =: octant image2
NB. relative address of neighbor, per gradient direction
nbr =: 4 2 $ _1 0, _1 _1, 0 _1, 1 _1


NB. mask for maximum gradient colinear with gradient
NB. mask for maximum colinear gradient
ok0 =: (0=og) *. krnl0 greatestOf image2
ok0 =: (0=og) *. (0{nbr) greatestOf image2
ok1 =: (1=og) *. krnl1 greatestOf image2
ok1 =: (1=og) *. (1{nbr) greatestOf image2
ok2 =: (2=og) *. krnl2 greatestOf image2
ok2 =: (2=og) *. (2{nbr) greatestOf image2
ok3 =: (3=og) *. krnl3 greatestOf image2
ok3 =: (3=og) *. (3{nbr) greatestOf image2
image3 =: image2 *. (ok0 +. ok1 +. ok2 +. ok3)
image3 =: image2 *. (ok0 +. ok1 +. ok2 +. ok3)

NB. Step 4 - Weak edge suppression
NB. Step 4 - Weak edge suppression