public Bitmap ToBitmap(double[,] image, PixelFormat pixelFormat) { double[,] imageCopy = (double[, ])image.Clone(); // Image is Grayscale // Each element is scaled to (0-255) range. int Width = imageCopy.GetLength(0); int Height = imageCopy.GetLength(1); Bitmap bitmap = new Bitmap(Width, Height, pixelFormat); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { // In case of a grayscale image, // each pixel has same R,G, and B values. double d = imageCopy[x, y]; int iii = Convert.ToInt32(d * 255.0); Color clr = Color.FromArgb(iii, iii, iii); bitmap.SetPixel(x, y, clr); } } Grayscale.SetPalette(bitmap); return(bitmap); }