本研究提出了一种基于OpenCV库的创新算法,专注于提升二值图像中边缘的平滑度和连续性,增强图像质量。
本段落实例分享了关于OpenCV的学习笔记中的一个应用:针对二值图像的边缘光滑处理(突出部消除)。具体内容如下:
该处理代码分为两个部分,第一部分用于去除边缘的突出部,第二部分则负责使边缘变得平滑。
以下是具体实现方式:
1. 去除边缘突出部
```cpp
// 函数用于去除二值图像中边缘的突出部。
// uthreshold、vthreshold分别表示了对于宽度和高度上突出部最小尺寸的要求阈值,
// type代表需要处理的颜色类型,0表示黑色(背景),1则代表白色(前景)。
void delete_jut(Mat& src, Mat& dst, int uthreshold, int vthreshold, int type){
// 根据type参数决定是删除黑点还是白点
if(type == 0) {
threshold = 255;
} else {
threshold = 0;
}
for(int i=1 ;i(i,j) == type &&
src.at(i+1, j) != type &&
src.at(i-1, j) != type &&
src.at(i, j+1) != type &&
src.at(i, j-1) != type){
int count = 0;
// 计算突出部的宽度和高度
for(int k=-uthreshold;k<=uthreshold;k++){
if(src.at(i,j+k)==type)
count++;
if(count > vthreshold){
break;
}
}
// 如果超出阈值,则将该点设为背景色
if (count <= vthreshold) {
dst.at(i, j)= threshold;
} else {
dst.at(i, j)= src.at(i,j);
}
}
}
}
}
```
这段代码通过遍历图像的每一个像素,检查该点是否为突出部,并根据设定的阈值判断其是否需要被去除。