/// <summary> /// Computes a 2-dimensional convolution filter for the provided sigma. /// </summary> /// <param name="stddev">Standard deviation of the Gaussian second derivative</param> /// <param name="orientation">Orientation of the filter</param> /// <returns>Convolution filter</returns> public static float[,] ComputeFilter(float stddev, float orientation) { int halfsize = (int)Math.Ceiling(stddev * 7); int size = halfsize * 2 + 1; float center = size * .5f; Gaussian gauss = new Gaussian(0, stddev * 3); GaussianSecondDerivative sd = new GaussianSecondDerivative(0, stddev); float[,] filter = new float[size, size]; float cos = (float)Math.Cos(orientation); float sin = (float)Math.Sin(orientation); for (int r = 0; r < size; r++) { for (int c = 0; c < size; c++) { float rTmp = r + .5f - center; float cTmp = c + .5f - center; float rr = sin * cTmp + cos * rTmp; float cc = cos * cTmp - sin * rTmp; float val1 = sd.Compute(rr); float val2 = gauss.Compute(cc); float value = val1 * val2; filter[r, c] = value; } } return(filter); }
/// <summary> /// Computes a 2-dimensional convolution filter for the provided sigma and point. /// </summary> /// <param name="column">Column of the point</param> /// <param name="row">Row of the point</param> /// <param name="size">Size of the patch</param> /// <param name="stddev">Standard deviation of the Gaussian second derivative</param> /// <returns>Convolution filter</returns> public static float[,] ComputeFilter(int size, int row, int column, float stddev) { Gaussian gauss = new Gaussian(0, stddev); float[,] filter = new float[size, size]; for (int r = 0; r < size; r++) { float dr = r + .5f - row; for (int c = 0; c < size; c++) { float dc = c + .5f - column; float distance = (float)Math.Sqrt(dr * dr + dc * dc); float value = gauss.Compute(distance); filter[r, c] = value; } } return(filter); }
/// <summary> /// Computes a 2-dimensional convolution filter for the provided sigma. /// </summary> /// <param name="stddev">Standard deviation of the Gaussian second derivative</param> /// <returns>Convolution filter</returns> public static float[,] ComputeFilter(float stddev) { int halfsize = (int)Math.Ceiling(stddev * 3); int size = halfsize * 2 + 1; float center = size * .5f; Gaussian gauss = new Gaussian(0, stddev); float[,] filter = new float[size, size]; for (int r = 0; r < size; r++) { float dr = r + .5f - center; for (int c = 0; c < size; c++) { float dc = c + .5f - center; float distance = (float)Math.Sqrt(dr * dr + dc * dc); float value = gauss.Compute(distance); filter[r, c] = value; } } return(filter); }