//二值图像的边界提取可以采用四领域或八领域方法:
//当前像素值为1,且周围四个(或8个)像素的值都为1,则此行列对应的结果图像的的像素为0
//否则保持不变
//本代码在vs2019调试通光。
#include <iostream>
using namespace std;
typedef unsigned char Byte;
void Edge4(Byte f[6][6], int h, int w, Byte mb, Byte g[6][6])
{ for (int y = 1; y < h-1; y++)
{ for (int x= 1; x < w-1; x++)
{ if (f[y][x] == mb && f[y + 1][x] == mb && f[y - 1][x] == mb
&& f[y][x+1] == mb && f[y][x-1] == mb
)//
g[y][x] = 1 - f[y][x];
else
g[y][x] = f[y][x];
}
cout << endl;
}
}
Byte a[6][6] ;
Byte b[6][6];
void initA()
{ for (int i = 0; i < 6; i++)
{ for (int j = 0; j < 6; j++)
a[i][j] = 1;
}
}
void printAStar()
{ for (int i = 0; i < 6; i++)
{ for (int j = 0; j < 6; j++)
{ if (a[i][j]) cout << "*";
else cout << " ";
}
cout << endl;
}
}
void printBStar()
{ for (int i = 0; i < 6; i++)
{ for (int j = 0; j < 6; j++)
{ if (b[i][j]) cout << "*";
else cout << " ";
}
cout << endl;
}
}
int main()
{ initA();
memcpy(b, a, 36);
printAStar();
Edge4(a, 6, 6, 1, b);
printBStar();
system("pause");
}