public static PNM ApplyHeightMapFunction(this PNM image, int matrixLength, Func <int, int, float[], int, Pixel> func) { PNM newImage = PNM.Copy(image); int padding = matrixLength / 2; Pad(newImage, padding); int newImageSize = newImage.Width * newImage.Height; float[] heightmap = new float[newImageSize]; byte r, g, b; for (int i = 0; i < newImageSize; i++) { newImage.GetPixel(i, out r, out g, out b); heightmap[i] = PNM.RGBToLuminosity(r, g, b) / 255f; } newImage = ApplyHeightMapFunctionCore(newImage.Width, newImage.Height, heightmap, matrixLength, func); Trim(newImage, padding); return(newImage); }