void Label(byte [,] f, int x,int y,byte L)//递归标记算法
{
f[x,y] = L;
if (f[x+1,y]==255) Label(f,x+1,y,L);
if (f[x-1,y]==255) Label(f,x-1,y,L);
if (f[x,y+1]==255) Label(f,x,y+1,L);
if (f[x,y-1]==255) Label(f,x,y-1,L);
if (f[x+1,y+1]==255) Label(f,x+1,y+1,L);
if (f[x-1,y+1]==255) Label(f,x-1,y+1,L);
if (f[x+1,y-1]==255) Label(f,x+1,y-1,L);
if (f[x-1,y-1]==255) Label(f,x-1,y-1,L);
}
void main()
{
byte [,]f = LoadImg();
if (f==null) return;
ShowImg("f",f);
int w = f.GetLength(0);
int h = f.GetLength(1);
//label the image
byte L = 1;
for (int y=0;y<h;y++)
for (int x=0;x<w;x++)
{