C++opencv之图像去噪(blur,GaussianBlur,medianBlur,f。。。

C++opencv之图像去噪(blur,GaussianBlur,medianBlur,f。。。
⽂章⽬录
上篇博客我们学到了图像添加噪声,这篇我们来学习图像去噪声。
OpenCV中常见的图像去噪声的⽅法有:干簧管传感器
-均值去噪声
-⾼斯模糊去噪声
-⾮局部均值去噪声
-双边滤波去噪声
-形态学去噪声
⼀、主要内容
这⾥均值去噪声、⾼斯模糊之前也讲过了,后⾯两个⽅法之后再讲。
1.1 均值去噪声
1.2 ⾼斯模糊去噪声
1.3 ⾮局部均值去噪声
L-Means的全称是:Non-Local Means,直译过来是⾮局部平均,在2005年由Baudes提出,该算法使⽤⾃然图像中普遍存在的冗余信息来去噪声。与常⽤的双线性滤波、中值滤波等利⽤图像局部信息来滤波不同的是,它利⽤了整幅图像来进⾏去噪,以图像块为单位在图像中寻相似区域,再对这些区域求平均,能够⽐较好地去掉图像中存在的⾼斯噪声。与我们以前学习的平滑技术相⽐这种算法要消耗更多的时间,但是结果很好。对于彩⾊图像,要先转换到 CIELAB 颜⾊空间,然后对 L 和 AB 成分分别去噪。
相关的函数有:
cv2.fastNlMeansDenoising()-使⽤单个灰度图像
cv2.fastNlMeansDenoisingColored()-使⽤彩⾊图像。
cv2.fastNlMeansDenoisingMulti()-⽤于在短时间内捕获的图像序列(灰度图像)机器人移动底盘
cv2.fastNlMeansDenoisingColoredMulti()-与上⾯相同,但⽤于彩⾊图像。
函数原型:
fastNlMeansDenoisingColored( InputArray src,
OutputArray dst,
float h =3,float hColor =3,
int templateWindowSize =7,int searchWindowSize =21)
共同参数有:
• h :决定过滤器强度。h 值⾼可以很好的去除噪声,但也会把图像的细节抹去。(取10的效果不错)
• hForColorComponents :与 h 相同,但使⽤与彩⾊图像。(与 h 相同,10)
• templateWindowSize :奇数。(推荐值为7)
• searchWindowSize :奇数。(推荐值为21)
1.4 双边滤波去噪声
1.5 形态学去噪声
⼆、代码演⽰
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
void add_salt_pepper_noise(Mat &image);
void gaussian_noise(Mat &image);led像素灯>给皂器
int main(int artc,char** argv){
Mat src =imread("C:\\Users\\Dell\\Desktop\\picture\\opencv_tutorial\\opencv_tutorial\\data\\images\\e
xample.png"); pty()){
printf("could not \n");
return-1;
}
namedWindow("input", WINDOW_AUTOSIZE);
imshow("input", src);cielab
gaussian_noise(src);
Mat result1, result2, result3, result4;
blur(src, result1,Size(5,5));
imshow("result-1", result1);
GaussianBlur(src, result2,Size(5,5),0);
imshow("result-2", result2);
medianBlur(src, result3,5);
imshow("result-3", result3);
fastNlMeansDenoisingColored(src, result4,15,15,10,30);
imshow("result-4", result4);
waitKey(0);
return0;
}
void add_salt_pepper_noise(Mat &image){
RNG rng(12345);
压电陶瓷超声换能器int h = ws;
int w = ls;
int nums =10000;
for(int i =0; i < nums; i++){
int x = rng.uniform(0, w);
int y = rng.uniform(0, h);
if(i %2==1){
image.at<Vec3b>(y, x)=Vec3b(255,255,255);
}
else{
image.at<Vec3b>(y, x)=Vec3b(0,0,0);
}
}
imshow("salt pepper", image);
}
void gaussian_noise(Mat &image){
Mat noise = Mat::zeros(image.size(), pe());
randn(noise,(15,15,15),(30,30,30));
Mat dst;
add(image, noise, dst);
imshow("gaussian noise", dst);
}
三、结果展⽰
这⾥我们可以看到去噪之后的图⽚。
这⾥我们看到后⾯两种⽅法的去噪结果,效果是相当好的。(类似市⾯上美图软件中的磨⽪)加油吧 阿超没有蛀⽛!

本文发布于:2024-09-24 15:21:56,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/3/336732.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:图像   噪声   滤波   算法   函数   上美   局部
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议