【发布时间】:2019-12-10 08:34:40
【问题描述】:
我的代码已经可以工作了,但是恕我直言,很丑:
public IList<OxyPlot.DataPoint> Points { get; private set; }
public IList<OxyPlot.DataPoint> Points2 { get; private set; }
void ApplyGaussFilter()
{
var gauss = MathNet.Numerics.Window.Gauss(5, 0.8);
Points2 = new List<OxyPlot.DataPoint>();
var inputArray = Points.ToArray();
for (int i=2; i< inputArray.Length-2; ++i)
{
double smoothedVal = (inputArray[i - 2].Y * gauss[0] +
inputArray[i - 1].Y * gauss[1] +
inputArray[i].Y * gauss[2] +
inputArray[i + 1].Y * gauss[3] +
inputArray[i + 2].Y * gauss[4]) / gauss.Sum();
Points2.Add(new DataPoint(inputArray[i].X, smoothedVal));
}
}
有没有更简单的方法?另外我不知道如何正确处理两个最外面的数组值。为了将高斯宽度从 5 更改为任何其他值,for 循环也需要手动更新。
到目前为止,我发现的所有示例都是基于图像来过滤这些的。例如。 guassian smoothening formula application。
与我丑陋的 for 循环相比,使用带有两行代码的图像库应用过滤器看起来要好得多。
GaussianBlur filter = new GaussianBlur(4, 11);
filter.ApplyInPlace(graph);
【问题讨论】:
标签: c# mathnet-numerics mathnet-filtering