public void GaussNoise() { var originalpicture = new Bitmap(Program.f1.pictureBox1.Image); BufferedBitmap original = new BufferedBitmap(originalpicture); original.Lock(); int width = original.Width; int height = original.Height; Bitmap rendered = new Bitmap(width, height); double z = 127; double O2 = 2 * trackBar1.Value; double O = 1 / (Math.Sqrt(Math.PI * O2)); double p = 0; int pixel; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { pixel = original.GetPixel(i, j).R; p = O * Math.Exp(-Math.Pow(pixel - z, 2) / O2); if (p != 0) { pixel = Random(p, pixel); } Color newColor = Color.FromArgb(pixel, pixel, pixel); rendered.SetPixel(i, j, newColor); } } original.Unlock(); Program.f1.pictureBox2.Image = rendered; }
public void ExpNoise() { var originalpicture = new Bitmap(Program.f1.pictureBox1.Image); BufferedBitmap original = new BufferedBitmap(originalpicture); original.Lock(); int width = original.Width; int height = original.Height; Bitmap rendered = new Bitmap(width, height); double a = trackBar1.Value; int pixel; double p = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixel = original.GetPixel(x, y).R; p = a * Math.Exp(-a * pixel); if (p != 0) { pixel = Random(p, pixel); } Color newColor = Color.FromArgb(pixel, pixel, pixel); rendered.SetPixel(x, y, newColor); } } original.Unlock(); Program.f1.pictureBox2.Image = rendered; }
public void ReleyNoise() { var originalpicture = new Bitmap(Program.f1.pictureBox1.Image); BufferedBitmap original = new BufferedBitmap(originalpicture); original.Lock(); int width = original.Width; int height = original.Height; Bitmap rendered = new Bitmap(width, height); double a = trackBar1.Value; double b1 = 2 / (double)trackBar2.Value; double b2 = trackBar2.Value; int pixel; double p = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixel = original.GetPixel(x, y).R; if (pixel >= a) { p = b1 * (pixel - a) * Math.Exp(-Math.Pow((pixel - a), 2) / b2); pixel = Random(p, pixel, 255); } Color newColor = Color.FromArgb(pixel, pixel, pixel); rendered.SetPixel(x, y, newColor); } } original.Unlock(); Program.f1.pictureBox2.Image = rendered; }
public void UniformNoise() { var originalpicture = new Bitmap(Program.f1.pictureBox1.Image); BufferedBitmap original = new BufferedBitmap(originalpicture); original.Lock(); int width = original.Width; int height = original.Height; Bitmap rendered = new Bitmap(width, height); double ab = 1 / (double)(trackBar2.Value - trackBar1.Value); int a = trackBar1.Value; int b = trackBar2.Value; int pixel; double p = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixel = original.GetPixel(x, y).R; if (pixel >= a && pixel <= b) { p = ab; pixel = Random(p, pixel, 255); } Color newColor = Color.FromArgb(pixel, pixel, pixel); rendered.SetPixel(x, y, newColor); } } original.Unlock(); Program.f1.pictureBox2.Image = rendered; }
public void ImpulsNoise() { var originalpicture = new Bitmap(Program.f1.pictureBox1.Image); BufferedBitmap original = new BufferedBitmap(originalpicture); original.Lock(); int width = original.Width; int height = original.Height; Bitmap rendered = new Bitmap(width, height); int a = trackBar1.Value; int b = trackBar2.Value; double Pa = (double)trackBar3.Value / 100; double p = 0; int pixel; int change = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixel = original.GetPixel(x, y).R; if (pixel == a) { p = Pa; Random r = new Random(Guid.NewGuid().GetHashCode()); if (r.Next(0, 100) > 50) { change = 255; } else { change = 0; } pixel = Random(p, pixel, change); } else if (pixel == b) { p = 1 - Pa; Random r = new Random(Guid.NewGuid().GetHashCode()); if (r.Next(0, 100) > 50) { change = 255; } else { change = 0; } pixel = Random(p, pixel, change); } Color newColor = Color.FromArgb(pixel, pixel, pixel); rendered.SetPixel(x, y, newColor); } } original.Unlock(); Program.f1.pictureBox2.Image = rendered; }
public Bitmap smoothing(ref Bitmap original, int size, double[,] mask) { double sumMask = 0; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { sumMask += mask[i, j]; } } int N = (size - 1) / 2; int C = 0; int m = 0; int n = 0; BufferedBitmap Origin = new BufferedBitmap(original); Origin.Lock(); Bitmap renderedImage = new Bitmap(original.Width, original.Height); for (int x = N; x < original.Width - N; x++) { for (int y = N; y < original.Height - N; y++) { for (int i = x - N; i <= x + N; i++) { for (int j = y - N; j <= y + N; j++) { var pixel = Origin.GetPixel(i, j); C += (int)(pixel.R * mask[m, n]); n++; } m++; n = 0; } C = (int)(Math.Round(C / sumMask)); Color newColor = Color.FromArgb(C, C, C); renderedImage.SetPixel(x, y, newColor); C = 0; m = 0; n = 0; } } Origin.Unlock(); return(renderedImage); }