二值图像轮廓提取
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;
}
// 轮廓提取
// 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;
}
相关文章推荐
- MYSQL---CREATE...SELECT
- Xcode 6 国际化
- MySQL无法启动几种常见问题小结
- C# 内存管理
- C# 内存管理
- Java如何从HttpServletRequest中读取HTTP请求的body
- MySQL Cluster 3台机器搭建集群环境
- repo管理多个git仓库
- BZOJ 2561 最小生成树 最小割
- 使用phpQuery实现批量文件处理
- 使用Sax解析器对XML文件进行解析并转化为JavaBean
- universal-image-loader 使用思路
- 使用记事本开发第一个java程序
- js 10秒钟倒计时
- 黑马程序员---c语言 指针的学习笔记
- zoj1713 Haiku Review
- H264文件通过RTP封装推送给VLC播放之sdp文件如何写?
- 迷途指针和空指针,malloc /new区别
- !function($){}(window.jQuery) 是什么意思
- 《ASP.NET》数据的绑定—Repeater