Stap 1: De Filters klasse
public class FilterMatrix { public static double[,] Laplacian3x3 { get { return new double[,] { { -1, -1, -1, }, { -1, 8, -1, }, { -1, -1, -1, }, }; } } public static double[,] Laplacian5x5 { get { return new double[,] { { -1, -1, -1, -1, -1, }, { -1, -1, -1, -1, -1, }, { -1, -1, 24, -1, -1, }, { -1, -1, -1, -1, -1, }, { -1, -1, -1, -1, -1 }, }; } } public static double[,] LaplacianOfGaussian { get { return new double[,] { { 0, 0, -1, 0, 0 }, { 0, -1, -2, -1, 0 }, { -1, -2, 16, -2, -1 }, { 0, -1, -2, -1, 0 }, { 0, 0, -1, 0, 0 }, }; } } public static double[,] Gaussian3x3 { get { return new double[,] { { 1, 2, 1, }, { 2, 4, 2, }, { 1, 2, 1, }, }; } } public static double[,] Gaussian5x5Type1 { get { return new double[,] { { 2, 04, 05, 04, 2 }, { 4, 09, 12, 09, 4 }, { 5, 12, 15, 12, 5 }, { 4, 09, 12, 09, 4 }, { 2, 04, 05, 04, 2 }, }; } } public static double[,] Gaussian5x5Type2 { get { return new double[,] { { 1, 4, 6, 4, 1 }, { 4, 16, 24, 16, 4 }, { 6, 24, 36, 24, 6 }, { 4, 16, 24, 16, 4 }, { 1, 4, 6, 4, 1 }, }; } } public static double[,] Sobel3x3Horizontal { get { return new double[,] { { -1, 0, 1, }, { -2, 0, 2, }, { -1, 0, 1, }, }; } } public static double[,] Sobel3x3Vertical { get { return new double[,] { { 1, 2, 1, }, { 0, 0, 0, }, { -1, -2, -1, }, }; } } public static double[,] Prewitt3x3Horizontal { get { return new double[,] { { -1, 0, 1, }, { -1, 0, 1, }, { -1, 0, 1, }, }; } } public static double[,] Prewitt3x3Vertical { get { return new double[,] { { 1, 1, 1, }, { 0, 0, 0, }, { -1, -1, -1, }, }; } } public static double[,] Kirsch3x3Horizontal { get { return new double[,] { { 5, 5, 5, }, { -3, 0, -3, }, { -3, -3, -3, }, }; } } public static double[,] Kirsch3x3Vertical { get { return new double[,] { { 5, -3, -3, }, { 5, 0, -3, }, { 5, -3, -3, }, }; } } }
Met behulp van de filters klasse
public void filter(string xfilter, string yfilter) { double[,] xFilterMatrix; double[,] yFilterMatrix; switch (xfilter) { case "Laplacian3x3": xFilterMatrix = FilterMatrix.Laplacian3x3; break; case "Laplacian5x5": xFilterMatrix = FilterMatrix.Laplacian5x5; break; case "LaplacianOfGaussian": xFilterMatrix = FilterMatrix.LaplacianOfGaussian; break; case "Gaussian3x3": xFilterMatrix = FilterMatrix.Gaussian3x3; break; case "Gaussian5x5Type1": xFilterMatrix = FilterMatrix.Gaussian5x5Type1; break; case "Gaussian5x5Type2": xFilterMatrix = FilterMatrix.Gaussian5x5Type2; break; case "Sobel3x3Horizontal": xFilterMatrix = FilterMatrix.Sobel3x3Horizontal; break; case "Sobel3x3Vertical": xFilterMatrix = FilterMatrix.Sobel3x3Vertical; break; case "Prewitt3x3Horizontal": xFilterMatrix = FilterMatrix.Prewitt3x3Horizontal; break; case "Prewitt3x3Vertical": xFilterMatrix = FilterMatrix.Prewitt3x3Vertical; break; case "Kirsch3x3Horizontal": xFilterMatrix = FilterMatrix.Kirsch3x3Horizontal; break; case "Kirsch3x3Vertical": xFilterMatrix = FilterMatrix.Kirsch3x3Vertical; break; default: xFilterMatrix = FilterMatrix.Laplacian3x3; break; } switch (yfilter) { case "Laplacian3x3": yFilterMatrix = FilterMatrix.Laplacian3x3; break; case "Laplacian5x5": yFilterMatrix = FilterMatrix.Laplacian5x5; break; case "LaplacianOfGaussian": yFilterMatrix = FilterMatrix.LaplacianOfGaussian; break; case "Gaussian3x3": yFilterMatrix = FilterMatrix.Gaussian3x3; break; case "Gaussian5x5Type1": yFilterMatrix = FilterMatrix.Gaussian5x5Type1; break; case "Gaussian5x5Type2": yFilterMatrix = FilterMatrix.Gaussian5x5Type2; break; case "Sobel3x3Horizontal": yFilterMatrix = FilterMatrix.Sobel3x3Horizontal; break; case "Sobel3x3Vertical": yFilterMatrix = FilterMatrix.Sobel3x3Vertical; break; case "Prewitt3x3Horizontal": yFilterMatrix = FilterMatrix.Prewitt3x3Horizontal; break; case "Prewitt3x3Vertical": yFilterMatrix = FilterMatrix.Prewitt3x3Vertical; break; case "Kirsch3x3Horizontal": yFilterMatrix = FilterMatrix.Kirsch3x3Horizontal; break; case "Kirsch3x3Vertical": yFilterMatrix = FilterMatrix.Kirsch3x3Vertical; break; default: yFilterMatrix = FilterMatrix.Laplacian3x3; break; }