C++简单实现膨胀腐蚀开闭运算
来源:互联网 发布:c 相关系数算法 编辑:程序博客网 时间:2024/05/16 08:29
项目需要用到闭运算对结果做形态学处理,简单实现一个仅供参考。
void Erosion(BYTE* image, BYTE* res, int nHeight, int nWidth)//二值图像膨胀{for (int i = 1; i < nHeight - 1; i++){for (int j = 1; j < nWidth - 1; j++){int pos = i*nWidth + j;int up = pos - nWidth;int upleft = pos - nWidth - 1;int upright = pos - nWidth + 1;int left = pos - 1;int right = pos + 1;int downleft = pos + nWidth - 1;int down = pos + nWidth;int downright = pos + nWidth + 1;(image[pos] || image[up] || image[upleft] || image[upright] || image[left] || image[right] || image[downleft] || image[down] || image[downright]) ? res[pos] = 255 : res[pos] = 0;}}for (int i = 0; i < 1; i++){for (int j = 0; j < nWidth; j++){int tmppos = i*nWidth + j;res[tmppos] = image[tmppos];}}for (int i = 1; i < nHeight - 1; i++){int tmppos1 = i*nWidth;res[tmppos1] = image[tmppos1];int tmppos2 = (i + 1)*nWidth - 1;res[tmppos2] = image[tmppos2];}for (int i = nHeight - 1; i < nHeight; i++){for (int j = 0; j < nWidth; j++){int tmppos = i*nWidth + j;res[tmppos] = image[tmppos];}}}void Dilation(BYTE* image, BYTE* res, int nHeight, int nWidth)//二值图像腐蚀{for (int i = 1; i < nHeight - 1; i++){for (int j = 1; j < nWidth - 1; j++){int pos = i*nWidth + j;int up = pos - nWidth;int upleft = pos - nWidth - 1;int upright = pos - nWidth + 1;int left = pos - 1;int right = pos + 1;int downleft = pos + nWidth - 1;int down = pos + nWidth;int downright = pos + nWidth + 1;(image[pos] && image[up] && image[upleft] && image[upright] && image[left] && image[right] && image[downleft] && image[down] && image[downright]) ? res[pos] = 255 : res[pos] = 0;}}for (int i = 0; i < 1; i++){for (int j = 0; j < nWidth; j++){int tmppos = i*nWidth + j;res[tmppos] = image[tmppos];}}for (int i = 1; i < nHeight - 1; i++){int tmppos1 = i*nWidth;res[tmppos1] = image[tmppos1];int tmppos2 = (i + 1)*nWidth - 1;res[tmppos2] = image[tmppos2];}for (int i = nHeight - 1; i < nHeight; i++){for (int j = 0; j < nWidth; j++){int tmppos = i*nWidth + j;res[tmppos] = image[tmppos];}}}void Closeoperations(BYTE* image, BYTE* res, int nHeight, int nWidth)//形态学闭操作{BYTE* transition = new BYTE[nHeight*nWidth];Erosion(image, transition, nHeight, nWidth);Dilation(transition, res, nHeight, nWidth);delete[]transition;}void Openoperations(BYTE* image, BYTE* res, int nHeight, int nWidth)//形态学开操作{BYTE* transition = new BYTE[nHeight*nWidth];Dilation(image, transition, nHeight, nWidth);Erosion(transition, res, nHeight, nWidth);delete[]transition;}
阅读全文
0 0
- C++简单实现膨胀腐蚀开闭运算
- 膨胀 腐蚀 开闭运算
- 图像膨胀腐蚀开闭运算
- 数字形态学 腐蚀膨胀 开闭运算详解
- OpenCV学习笔记-形态学操作-腐蚀膨胀-开闭运算
- Matlab 图像处理 形态学 腐蚀 膨胀 开闭运算 连通分量
- opencv 的开闭,腐蚀膨胀运算的例子。
- Matlab 图像处理 形态学 腐蚀 膨胀 开闭运算 连通分量
- Matlab 图像处理 形态学 腐蚀 膨胀 开闭运算 连通分量
- Matlab 图像处理 形态学 腐蚀 膨胀 开闭运算 连通分量
- Matlab 图像处理 形态学 腐蚀 膨胀 开闭运算 连通分量
- Matlab 图像处理 形态学 腐蚀 膨胀 开闭运算 连通分量
- 图像的膨胀与腐蚀以及开闭运算
- java实现的图像腐蚀、膨胀运算
- 【数字图像处理】图像二值化,腐蚀膨胀,开闭运算,击中击不中变换
- 数学形态学之二值形态学(腐蚀、膨胀、开闭运算)基本原理
- OpenCV形态学操作 腐蚀 膨胀 开闭
- OpenCV形态学操作 腐蚀 膨胀 开闭
- 如何转载别人的文章
- SimpleDateFormat和DateFormat的基本使用(format和prase)
- Windows下加速SourceTree的方法
- msyql中子查询IN,EXISTS,ANY,ALL,SOME,UNION介绍
- Zookeeper原理
- C++简单实现膨胀腐蚀开闭运算
- C++ 测试覆盖率统计轻量方案-gtest+lcov
- ios 图片裁剪
- 第1周第1次课 数据结构总览
- bzoj 1667: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛(BFS)
- Spring IOC和DI
- svn: line 19: Option expected
- linux创建空洞文件
- 设计模式----工厂模式