public static void Gray(BMPImage image) { for (int x = 0; x < image.Width; x++) { for (int y = 0; y < image.Height; y++) { Pixel pixel = image.GetPixel(x, y); int sum = pixel.Red + pixel.Green + pixel.Blue; pixel.Red = pixel.Green = pixel.Blue = (byte)(sum / 3); image.SetPixel(pixel, x, y); } } }
public static void UseMatrix(BMPImage image, float[,] kernel) { float red; float green; float blue; Pixel[,] copy = new Pixel[image.Width, image.Height]; for (int x = 1; x < image.Width - 1; x++) { for (int y = 1; y < image.Height - 1; y++) { red = 0; green = 0; blue = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { red += image.GetPixel(x + i - 1, y + j - 1).Red *kernel[i, j]; green += image.GetPixel(x + i - 1, y + j - 1).Green *kernel[i, j]; blue += image.GetPixel(x + i - 1, y + j - 1).Blue *kernel[i, j]; } } red = Math.Abs(red); green = Math.Abs(green); blue = Math.Abs(blue); copy[x, y] = new Pixel((byte)red, (byte)green, (byte)blue); } } for (int x = 1; x < image.Width - 1; x++) { for (int y = 1; y < image.Height - 1; y++) { image.SetPixel(copy[x, y], x, y); } } }
public static void Median(BMPImage image) { byte[] red = new byte[9]; byte[] green = new byte[9]; byte[] blue = new byte[9]; Pixel[,] copy = new Pixel[image.Width, image.Height]; for (int x = 1; x < image.Width - 1; x++) { for (int y = 1; y < image.Height - 1; y++) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { red[3 * i + j] = image.GetPixel(x + i - 1, y + j - 1).Red; green[3 * i + j] = image.GetPixel(x + i - 1, y + j - 1).Green; blue[3 * i + j] = image.GetPixel(x + i - 1, y + j - 1).Blue; } } Array.Sort(red); Array.Sort(green); Array.Sort(blue); copy[x, y] = new Pixel(red[4], green[4], blue[4]); } } for (int x = 1; x < image.Width - 1; x++) { for (int y = 1; y < image.Height - 1; y++) { image.SetPixel(copy[x, y], x, y); } } }