我正在尝试通过opencv fastNlMeansDenoising()函数消除噪声。但是我的输出图像与原始噪点图像相同。
输入图片:
码:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int main() {
Mat img = imread("noisy.jpg");
if (!img.data) {
cout << "File not found" << endl;
return -1;
}
// first copy the image
Mat img_gray = img.clone();
cvtColor(img, img_gray, CV_RGB2GRAY);
Mat img1;
//fastNlMeansDenoising(img_gray, img1, 3.0, 7, 21);
cv::fastNlMeansDenoising(img_gray, img1, 3.0, 7, 21);
imshow("img1", img1);
waitKey();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出图像:
我看不到任何平滑效果。我不明白原因。请帮助我使用此功能消除噪音。谢谢
在opencv中,函数定义如下
void fastNlMeansDenoising(InputArray src, OutputArray dst, float h=3, int templateWindowSize=7, int searchWindowSize=21 )
Run Code Online (Sandbox Code Playgroud)
哪里
Parameters:
src – Input 8-bit 1-channel, 2-channel or 3-channel image.
dst – Output image with the same size and type as src .
templateWindowSize – Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels
searchWindowSize – Size in pixels of the window that is used to compute weighted average for given pixel. Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels
h – Parameter regulating filter strength. Big h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise
Run Code Online (Sandbox Code Playgroud)
因此,为了消除噪声,我必须增加滤波器强度参数h,较大的h值可以完全消除噪声,但是较小的h值可以保留细节,还可以保留一些噪声。
所以我可以通过使用这样的功能来完美消除噪音。
fastNlMeansDenoising(img_gray, img1, 30.0, 7, 21);
Run Code Online (Sandbox Code Playgroud)
输出:
注意:在调试模式下,此函数的执行时间太慢。为了加快执行时间,最好在发布模式下运行它。
希望这对干杯有帮助
| 归档时间: |
|
| 查看次数: |
7518 次 |
| 最近记录: |