m = 10; n =8;
A = randint(m,n,[0 1])
R = [];
for r = 2:m-1
for c = 2:n-1
a = A(r-1:r+1,c-1:c+1);
% 正中元素
L0 = A(r,c)==0;
% 上下左右
b1 = [A(r-1,c),A(r+1,c),A(r,c-1),A(r,c+1)];
L1 = length(find(b1==0))==3;
% 左上左下右上右下
b2 = [A(r-1,c-1),A(r+1,c-1),A(r-1,c+1),A(r+1,c+1)];
L2 = length(find(b2==0))==2;
if L0 & L1 & L2
R = [R; [r c]];
a
end
end
end
R
A =
0 0 0 1 0 0 0 0
0 0 0 0 1 1 0 0
1 0 0 0 0 0 1 0
1 0 0 1 1 1 1 1
0 1 0 0 1 0 1 1
0 0 1 1 1 0 1 1
1 1 0 1 0 0 0 1
0 0 0 1 0 0 0 0
1 0 0 1 0 1 1 1
1 1 1 0 0 0 1 1
a =
0 0 1
0 0 0
0 1 1
a =
1 1 0
0 0 0
1 0 0
R =
3 4
8 2
遍历8个边上的元素是否为0呗