/// <summary> /// Create a 2D filter kernel matrix populated in accordance with /// filterKernelFun, with size (SX, SY) = (2 * radius + 1, /// 2 * radius + 1) and anchor in the center at index (0, 0). /// Functions to use as filterKernelFun are available in FilterKernelFun. /// </summary> /// <param name="radius"></param> /// <param name="filterKernelFun">Function is evaluated at integer coordinates from (-radius,-radius) to (+radius,+radius).</param> public static Matrix <float> Create2DKernel( long radius, Func <float, float, float> filterKernelFun) { var kernel = new Matrix <float>(2 * radius + 1, 2 * radius + 1) { FX = -radius, FY = -radius }; kernel.SetByCoord((long x, long y) => filterKernelFun((float)x, (float)y)); return(kernel); }
/// <summary> /// Computes an undistorted Grid with (count.X + 1, count.Y + 1) vertices /// the coordinates are roughly in the range [0..imageSize.X, 0..imageSize.Y]. /// These can be used for a piecewise linear undistortion using the graphics /// card. If count is not given, it is set to iamgeSize / 8, for one grid /// point each 8 pixels. /// </summary> Matrix <V2f> ComputeUndistortedGrid(V2i imageSize, V2i count = default(V2i)) { if (count == default(V2i)) { count = imageSize / 8; } var grid = new Matrix <V2f>(count + V2i.II); var delta = imageSize.ToV2d() / count.ToV2d(); var self = this; grid.SetByCoord((x, y) => self.UndistortPixel(new V2d(x * delta.X, y * delta.Y), imageSize).ToV2f()); return(grid); }