cc++ 二值图像 边界提取

cc++ 二值图像 边界提取,第1张

//二值图像的边界提取可以采用四领域或八领域方法:

//当前像素值为1,且周围四个(或8个)像素的值都为1,则此行列对应的结果图像的的像素为0

//否则保持不变

//本代码在vs2019调试通光。

 #include

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");
}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1295853.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-10
下一篇2022-06-10

发表评论

登录后才能评论

评论列表(0条)

    保存