Canny edge detector: Difference between revisions

m
Line 698:
unique =: 3 : 'y*i.$y'
connect =: 3 : 'attach^:_ unique y'
octant =: 3 : '4|(>.(_0.5+((4%(o. 1))*(12&o. y))))' NB. eighth of circle
 
canny =: 3 : 0
Line 715 ⟶ 716:
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)
 
Line 724 ⟶ 723:
NB. is this gradient the greatest of immmediate colinear neighbore?
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
NB. relative address of neighbor, relevantper to gradgradient direction
nbr =: 4 2 $ _1 0, _1 _1, 0 _1, 1 _1
 
NB. mask for maximum gradient colinear with gradient
ok0 =: (0=og) *. krnl0(0{nbr) greatestOf image2
ok1 =: (1=og) *. krnl1(1{nbr) greatestOf image2
ok2 =: (2=og) *. krnl2(2{nbr) greatestOf image2
ok3 =: (3=og) *. krnl3(3{nbr) greatestOf image2
image3 =: image2 *. (ok0 +. ok1 +. ok2 +. ok3)
 
NB. Step 4 - Weak edge suppression