我想应用我在标题中命名的基于以下等式的去噪滤波器:
其中 d = 1
是标量常数扩散参数,I(x, y)
是初始噪声图像,u(x, y, t)
是扩散时间 t
之后获得的图像,比方说 5、10 和 30
。但是,为了在 OpenCV 中实现这一点,我对使用哪个函数以及如何使用感到很困惑。我觉得这很简单,但出于某种原因我很困惑。有人有想法吗?
这是一个示例图片:
然后我想将它与根据以下内容的高斯滤波方法进行比较:
其中 G√2t (x, y)
是高斯核。这证明在 d = 1
的时间 t
上执行各向同性线性扩散完全等同于在 σ = √(2t)
上执行高斯平滑>
我有一个应用高斯滤波的函数:
void gaussian_2D_convolution(const cv::Mat& src, cv::Mat& dst, const float sigma, const int ksize_x = 0, const int ksize_y = 0)
{
int ksize_x_ = ksize_x, ksize_y_ = ksize_y;
// Compute an appropriate kernel size according to the specified sigma
if (sigma > ksize_x || sigma > ksize_y || ksize_x == 0 || ksize_y == 0)
{
ksize_x_ = (int)ceil(2.0f*(1.0f + (sigma - 0.8f) / (0.3f)));
ksize_y_ = ksize_x_;
}
// The kernel size must be and odd number
if ((ksize_x_ % 2) == 0)
{
ksize_x_ += 1;
}
if ((ksize_y_ % 2) == 0)
{
ksize_y_ += 1;
}
// Perform the Gaussian Smoothing
GaussianBlur(src, dst, Size(ksize_x_, ksize_y_), sigma, sigma, BORDER_DEFAULT);
// show result
std::ostringstream out;
out << std::setprecision(1) << std::fixed << sigma;
String title = "sigma: " + out.str();
imshow(title, dst);
imwrite("gaussian/" + title + ".png", dst);
waitKey(260);
}
但我在实现第一个案例时遇到困难。
这应该按预期工作。这是基于:
代码:
#include <opencv2\opencv.hpp>
using namespace cv;
void ilds(const Mat1b& src, Mat1b& dst, int iter = 10, double diffusivity = 1.0, double lambda = 0.1)
{
Mat1f img;
src.convertTo(img, CV_32F);
lambda = fmax(0.001, std::fmin(lambda, 0.25)); // something in [0, 0.25] by default should be 0.25
while (iter--)
{
Mat1f lap;
Laplacian(img, lap, CV_32F);
img += lambda * diffusivity * lap;
}
img.convertTo(dst, CV_8U);
}
int main() {
Mat1b img = imread("path_to_image", IMREAD_GRAYSCALE);
Mat1b res_ilds;
ilds(img, res_ilds);
imshow("ILDS", res_ilds);
waitKey();
return 0;
}
结果:
让我知道它是否适合你
我是一名优秀的程序员,十分优秀!