public Image <Rgb24> ApplyFilter(double[,] filterMask, int matrixSize, IFilter filter) { var image = Image.Clone(); var margin = (int)Math.Floor(matrixSize / 2f); for (int i = margin; i < image.Width - margin; i++) { for (int j = margin; j < image.Height - margin; j++) { image[i, j] = filter.Compute(GetNeighbourhood(Image, i, j, margin, matrixSize), filterMask, matrixSize); } } return(image); }