The way you've defined your edges they correspond to either transition from 0 to 1 or from 1 to 0 when scanning from left to right or top to bottom. This is easily detected bydiff:
m = [0 0 0 0 0 0 0 0 1 1 ;
0 0 0 0 0 0 0 0 1 1 ;
0 0 0 0 0 0 0 1 1 1 ;
0 0 0 0 0 0 1 1 1 0 ;
0 0 0 0 0 1 1 1 1 0 ;
0 1 1 1 1 0 0 0 0 0 ;
1 1 1 1 1 0 0 0 0 0 ;
1 1 1 1 1 0 0 0 0 0 ;
1 1 1 1 0 0 0 0 0 0 ;
1 1 1 0 0 0 0 0 0 0 ; ]
m2 = [zeros(1, size(m, 2)); diff(m) == 1] | ... 0 to 1 from top to bottom
[diff(m) == -1; zeros(1, size(m, 2))] | ... 1 to 0 from top to bottom
[zeros(size(m, 1), 1), diff(m, [], 2) == 1] | ... 0 to 1 from left to right
[diff(m, [], 2) == -1, zeros(size(m, 1), 1)] % 1 to 0 from left to right
Best Answer