fastNlMeansDenoising()不会滤除噪音

时间:2016-06-20 05:50:02

标签: c++ opencv

我试图通过opencv fastNlMeansDenoising()函数去除噪音。 但我的输出图像与原始的噪声图像相同。

输入图片:

enter image description here

代码:

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

输出图片:

enter image description here

我看不到平滑效果。我不明白它的原因。 请帮我使用此功能去除噪音。谢谢

1 个答案:

答案 0 :(得分:5)

在opencv中,函数定义如下

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值保留细节并且还保留一些噪声。

所以我通过使用这样的功能完全消除噪音。

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

输出

denoise image with filter strength 30

注意:此功能在调试模式下执行时间太慢。对于一点点快速执行时间,最好在发布模式下运行它。

希望这会有所帮助 干杯