/*
加噪,去噪
*/
#include<opencv2\opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main() {
double t0 = (double)getTickCount();
Mat img_org = imread("D://图片//5.jpg");
if (img_org.empty()) {
cout << "图片加载失败!" << endl;
return -1;
}
Mat noisy = img_org.clone(); //复制图像
Mat noise(img_org.size(), img_org.type()); //制造噪声
randn(noise, 0, 100);
noisy += noise; //将噪声加载在图片上
Mat result;
fastNlMeansDenoisingColored(noisy, result,30,30); //最后的两个值越大效果越明显
imshow("noisy", noisy);
imshow("result", result);
double elapsed = ((double)getTickCount() - t0) / getTickFrequency(); //显示运行时间
cout << "t = " << elapsed << endl;
waitKey(0);
destroyAllWindows;
return 0;
}
运行结果: