gpt4 book ai didi

c++ - fastNlMeansDenoising() 不滤除噪声

转载 作者:太空狗 更新时间:2023-10-29 20:36:33 30 4
gpt4 key购买 nike

我正在尝试通过 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

我看不到任何平滑效果。我不明白这是为什么。请帮助我使用此功能来消除噪音。谢谢

最佳答案

在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 usedto compute weights. Should be odd. Recommended value 7 pixels

searchWindowSize – Size in pixels of the window that is used tocompute weighted average for given pixel. Should be odd. Affectperformance linearly: greater

searchWindowsSize - greater denoisingtime. Recommended value 21 pixels

h – Parameter regulating filterstrength. Big h value perfectly removes noise but also removes imagedetails, smaller h value preserves details but also preserves somenoise

因此,为了去除噪声,我不得不增加滤波器强度参数h,大的h值完美地去除了噪声,但较小的h值保留了细节,也保留了一些噪声。

所以我通过使用这样的函数完美地消除了噪声:

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

输出:

denoise image with filter strength 30

注意:此函数在 Debug模式下的执行时间太慢。为了稍微加快执行时间,最好在 Release模式下运行它。

关于c++ - fastNlMeansDenoising() 不滤除噪声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37915358/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com