您的位置:首页 > 其它

二值图像轮廓提取

2015-07-24 18:33 260 查看
二值图像轮廓提取只需要挖空内部像素点即可。亮点的8个相邻像素点全部为亮点,则该点为内部点,反之为轮廓点。将所有内部点置为背景点,完成轮廓提取。

// 轮廓提取

// 1. pImageData 图像数据

// 2. nWidth 图像宽度

// 3. nHeight 图像高度

// 4. nWidthStep 图像行大小

bool FindContours(unsigned char *pImageData, int nWidth, int nHeight, int nWidthStep)

{

int i = 0;

int j = 0;

unsigned char *pLine[3] = { NULL, NULL, NULL };

for (j = 1; j < nHeight - 1; j++)

{

pLine[0] = pImageData + nWidthStep * (j - 1);

pLine[1] = pImageData + nWidthStep * j;

pLine[2] = pImageData + nWidthStep * (j + 1);

for (i = 1; i < nWidth - 1; i++)

{

if (pLine[0][i-1] == 0xFF && pLine[0][i] == 0xFF && pLine[0][i+1] == 0xFF &&

pLine[1][i-1] == 0xFF && pLine[1][i] == 0xFF && pLine[1][i+1] == 0xFF &&

pLine[2][i-1] == 0xFF && pLine[2][i] == 0xFF && pLine[2][i+1] == 0xFF)

{

pLine[0][i-1] = 0;

}

else

{

pLine[0][i-1] = pLine[1][i];

}

}

}

return true;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: