public static double[,] Smoothing(double[,] img, double sigma) { var kernel = KernelHelper.MakeKernel((x, y) => Gaussian.Gaussian2D(x, y, sigma), KernelHelper.GetKernelSizeForGaussianSigma(sigma)); double[,] data = ConvolutionHelper.Convolve(img, kernel); return(data); }
public static Complex[,] EstimatePS(double[,] img, double Sigma1, double Sigma2) { var z = GetSquaredDerectionField(img, Sigma1); var kernel2 = KernelHelper.MakeComplexKernel((x, y) => Gaussian.Gaussian2D(x, y, Sigma2) * x / (x == 0 && y == 0 ? 1 : Math.Sqrt(x * x + y * y)), (x, y) => Gaussian.Gaussian2D(x, y, Sigma2) * y / (x == 0 && y == 0 ? 1 : Math.Sqrt(x * x + y * y)), KernelHelper.GetKernelSizeForGaussianSigma(Sigma2)); var I20 = ConvolutionHelper.ComplexConvolve(z, kernel2); return(I20); }
public static Complex[,] EstimateLS(double[,] l1, double Sigma1, double Sigma2) { var kernelX = KernelHelper.MakeKernel((x, y) => Gaussian.Gaussian2D(x, y, Sigma1) * x, KernelHelper.GetKernelSizeForGaussianSigma(Sigma1)); var resultX = ConvolutionHelper.Convolve(l1, kernelX); var kernelY = KernelHelper.MakeKernel((x, y) => Gaussian.Gaussian2D(x, y, Sigma1) * -y, KernelHelper.GetKernelSizeForGaussianSigma(Sigma1)); var resultY = ConvolutionHelper.Convolve(l1, kernelY); var preZ = KernelHelper.MakeComplexFromDouble(resultX, resultY); var z = preZ.Select2D(x => x * x); var kernel2 = KernelHelper.MakeComplexKernel((x, y) => Gaussian.Gaussian2D(x, y, Sigma2), (x, y) => 0, KernelHelper.GetKernelSizeForGaussianSigma(Sigma2)); var I20 = ConvolutionHelper.ComplexConvolve(z, kernel2); var I11 = ConvolutionHelper.Convolve(z.Select2D(x => x.Magnitude), kernel2.Select2D(x => x.Real)); Complex[,] LS = KernelHelper.Zip2D(I20, I11, (x, y) => x / y); return(LS); }
public static double[,] GenerateOrientationField(double[,] bytes) { double size = 1; double avSigma = 5; var kernelAv = KernelHelper.MakeKernel((x, y) => Gaussian.Gaussian2D(x, y, avSigma), KernelHelper.GetKernelSizeForGaussianSigma(avSigma)); var kernelX = KernelHelper.MakeKernel((x, y) => Gaussian.Gaussian2D(x, y, size) * x, KernelHelper.GetKernelSizeForGaussianSigma(size)); var dx = ConvolutionHelper.Convolve(bytes, kernelX); var kernelY = KernelHelper.MakeKernel((x, y) => Gaussian.Gaussian2D(x, y, size) * -y, KernelHelper.GetKernelSizeForGaussianSigma(size)); var dy = ConvolutionHelper.Convolve(bytes, kernelY); var Gxx = dx.Select2D(x => x * x); var Gxy = dx.Select2D((x, row, column) => x * dy[row, column]); var Gyy = dy.Select2D(x => x * x); Gxx = ConvolutionHelper.Convolve(Gxx, kernelAv); Gxy = ConvolutionHelper.Convolve(Gxy, kernelAv); Gyy = ConvolutionHelper.Convolve(Gyy, kernelAv); var angles = Gxx.Select2D((gxx, row, column) => 0.5 * Math.Atan2(2.0 * Gxy[row, column], gxx - Gyy[row, column])); angles = angles.Select2D(angle => angle <= 0 ? angle + Math.PI / 2 : angle - Math.PI / 2); //ImageHelper.SaveFieldAbove(bytes, angles, "C:\\temp\\orField.png"); //ImageHelper.SaveArray(angles, "C:\\temp\\angles.png"); return(angles); }
public double[,] GaussFilter() { double[,] filterX = new double[, ] { { -3, 0, 3 }, { -10, 0, 10 }, { -3, 0, 3 } }; double[,] filterY = new double[, ] { { 3, 10, 3 }, { 0, 0, 0 }, { -3, -10, -3 } }; double[,] Gx = ConvolutionHelper.Convolve(pic, filterX); double[,] Gy = ConvolutionHelper.Convolve(pic, filterY); double[,] X2 = new double[height, width]; double[,] Y2 = new double[height, width]; double[,] XY = new double[height, width]; for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) { X2[i, j] = Gx[i, j] * Gx[i, j]; Y2[i, j] = Gy[i, j] * Gy[i, j]; XY[i, j] = Gx[i, j] * Gy[i, j]; } } double sigma = 0.5; int size = KernelHelper.GetKernelSizeForGaussianSigma(sigma); double[,] w = KernelHelper.MakeKernel((x, y) => Gaussian.Gaussian2D(x, y, sigma), size); //Gaussian filter double[,] A = ConvolutionHelper.Convolve(X2, w); double[,] B = ConvolutionHelper.Convolve(Y2, w); double[,] C = ConvolutionHelper.Convolve(XY, w); double[,] R = new double[height, width]; for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) { double[,] M = new double[2, 2]; M[0, 0] = A[i, j]; M[0, 1] = C[i, j]; M[1, 0] = C[i, j]; M[1, 1] = B[i, j]; double Tr = M[0, 0] + M[1, 1]; double Det = M[0, 0] * M[1, 1] - M[1, 0] * M[0, 1]; R[i, j] = Det / Tr; } } double[,] matrix = new double[width, height]; for (int i = 0; i < width; ++i) { for (int j = 0; j < height; ++j) { matrix[i, j] = R[height - 1 - j, i]; } } return(matrix); }
public static Complex[,] GetSquaredDerectionField(double[,] img, double Sigma1) { var kernelX = KernelHelper.MakeKernel((x, y) => Gaussian.Gaussian2D(x, y, Sigma1) * x, KernelHelper.GetKernelSizeForGaussianSigma(Sigma1)); var resultX = ConvolutionHelper.Convolve(img, kernelX); var kernelY = KernelHelper.MakeKernel((x, y) => Gaussian.Gaussian2D(x, y, Sigma1) * -y, KernelHelper.GetKernelSizeForGaussianSigma(Sigma1)); var resultY = ConvolutionHelper.Convolve(img, kernelY); var preZ = KernelHelper.MakeComplexFromDouble(resultX, resultY); var z = preZ.Select2D(x => x * x); return(z); }
public static Complex[,] EsimateH2(double[,] img, double Sigma1, double Sigma2) { var z = GetSquaredDerectionField(img, Sigma1); var kernel2 = KernelHelper.MakeComplexKernel((x, y) => Gaussian.Gaussian2D(x, y, Sigma2) * x, (x, y) => Gaussian.Gaussian2D(x, y, Sigma2) * (-y), KernelHelper.GetKernelSizeForGaussianSigma(Sigma2)); var I20 = ConvolutionHelper.ComplexConvolve(z, kernel2); return(I20); }
public static double[,] Reduce2(double[,] source, double factor) { var smoothed = ConvolutionHelper.Convolve(source, KernelHelper.MakeKernel( (x, y) => Gaussian.Gaussian2D(x, y, factor / 2d * 0.75d), KernelHelper.GetKernelSizeForGaussianSigma(factor / 2d * 0.75d))); var result = new double[(int)(source.GetLength(0) / factor), (int)(source.GetLength(1) / factor)]; Resize(smoothed, result, factor, (x, y) => Gaussian.Gaussian2D(x, y, factor / 2d * 0.75d)); return(result); }