fastNlMeansDenoising()不会滤除噪声 [英] fastNlMeansDenoising() does not filter out noise

查看:1023
本文介绍了fastNlMeansDenoising()不会滤除噪声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过opencv fastNlMeansDenoising()函数消除噪声. 但是我的输出图像与原始噪点图像相同.

I am trying to remove noise by opencv fastNlMeansDenoising() function. But My output image is same like original noised image.

输入图片:

代码:

#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;
}

输出图像:

我看不到任何平滑效果.我不明白原因. 请帮助我使用此功能消除噪音.谢谢

I can not see any effect of smoothing. I do not understand reason of it. Please help me to use this function for removing noise. thanks

推荐答案

在opencv中,该函数定义如下

In opencv, the function is defined as follows

void fastNlMeansDenoising(InputArray src, OutputArray dst, float h=3, int templateWindowSize=7, int searchWindowSize=21 )

其中

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

因此,为了消除噪声,我必须增加滤波器强度参数h,较大的h值可以完全消除噪声,但是较小的h值可以保留细节,还可以保留一些噪声.

Therefore, In order to remove noise, i have to increase filter strength parameter h, big h value perfectly remove noise, but smaller h value preserves details and also preserve some noise.

所以我可以使用这样的功能完美地消除噪音.

So i perfectly remove noise by using the function like this .

fastNlMeansDenoising(img_gray, img1, 30.0, 7, 21);

输出:

注意:在调试模式下,此函数的执行时间太慢.为了加快执行时间,最好在发布模式下运行它.

Note: this function execute time is too slow in debug mode. For little bit fast execution time, better to run it in release mode.

希望这会有所帮助 干杯

Hope this helps Cheers

这篇关于fastNlMeansDenoising()不会滤除噪声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆