public override Bitmap processImage(Bitmap sourceImage, BackgroundWorker worker) { Bitmap result = new Bitmap(sourceImage.Width, sourceImage.Height); Filters filter1 = new Dilation(mask); Bitmap result1 = filter1.processImage(sourceImage, worker); Filters filter2 = new Erosion(mask); Bitmap result2 = filter2.processImage(sourceImage, worker); for (int i = 0; i < sourceImage.Width; i++) { worker.ReportProgress((int)((float)i / sourceImage.Width * 100)); if (worker.CancellationPending) { return(null); } for (int j = 0; j < sourceImage.Height; j++) { int newR = Clamp(result1.GetPixel(i, j).R - result2.GetPixel(i, j).R, 0, 255); int newG = Clamp(result1.GetPixel(i, j).G - result2.GetPixel(i, j).G, 0, 255); int newB = Clamp(result1.GetPixel(i, j).B - result2.GetPixel(i, j).B, 0, 255); result.SetPixel(i, j, Color.FromArgb(newR, newG, newB)); } } return(result); }
public override Bitmap processImage(Bitmap sourceImage, BackgroundWorker worker) { Bitmap resultImage = new Bitmap(sourceImage.Width, sourceImage.Height); Filters filter1 = new Dilation(mask); Bitmap result = filter1.processImage(sourceImage, worker); Filters filter2 = new Erosion(mask); result = filter2.processImage(result, worker); return(result); }
private void applyButton_Click(object sender, EventArgs e) { Filters filter; switch (buttonMode) { case 1: filter = new SepiaFilter(trackBar1.Value); backgroundWorker1.RunWorkerAsync(filter); break; case 2: filter = new BrightnessFilter(trackBar1.Value); backgroundWorker1.RunWorkerAsync(filter); break; case 3: filter = new SobelFilter(orientMode); backgroundWorker1.RunWorkerAsync(filter); break; case 4: if (textBoxHor.Text == "") { textBoxHor.Text = "0"; } if (textBoxVert.Text == "") { textBoxVert.Text = "0"; } filter = new Move(Convert.ToInt32(textBoxHor.Text), Convert.ToInt32(textBoxVert.Text)); backgroundWorker1.RunWorkerAsync(filter); break; case 5: if (textBoxHor.Text == "") { textBoxHor.Text = "0"; } if (textBoxVert.Text == "") { textBoxVert.Text = "0"; } filter = new Turn(Convert.ToInt32(textBoxHor.Text) - Convert.ToInt32(textBoxVert.Text)); backgroundWorker1.RunWorkerAsync(filter); break; case 6: filter = new Waves(trackBar1.Value, orientMode); backgroundWorker1.RunWorkerAsync(filter); break; case 7: filter = new Glass(trackBar1.Value); backgroundWorker1.RunWorkerAsync(filter); break; case 8: filter = new BorderSelection(trackBar1.Value, orientMode); backgroundWorker1.RunWorkerAsync(filter); break; case 9: filter = new MedianFilter(); backgroundWorker1.RunWorkerAsync(filter); break; case 10: filter = new MaximumFilter(); backgroundWorker1.RunWorkerAsync(filter); break; case 11: filter = new GlowingBorders(trackBar1.Value); backgroundWorker1.RunWorkerAsync(filter); break; case 12: filter = new Dilation(trackBar1.Value); backgroundWorker1.RunWorkerAsync(filter); break; case 13: filter = new Erosion(trackBar1.Value); backgroundWorker1.RunWorkerAsync(filter); break; case 14: filter = new InvertFilter(); backgroundWorker1.RunWorkerAsync(filter); break; case 15: filter = new BlurFilter(); backgroundWorker1.RunWorkerAsync(filter); break; case 16: filter = new GaussianFilter(); backgroundWorker1.RunWorkerAsync(filter); break; case 17: filter = new GreyScaleFilter(); backgroundWorker1.RunWorkerAsync(filter); break; case 18: filter = new SharpnessFilter(); backgroundWorker1.RunWorkerAsync(filter); break; case 19: filter = new SharpnessFilter2(); backgroundWorker1.RunWorkerAsync(filter); break; case 20: EmbossingFilter filter_ = new EmbossingFilter(); backgroundWorker1.RunWorkerAsync(filter_); break; case 21: GreyWorldFilter _filter_ = new GreyWorldFilter(); backgroundWorker1.RunWorkerAsync(_filter_); break; case 22: filter = new HistogramSretching(); backgroundWorker1.RunWorkerAsync(filter); break; case 23: filter = new Opening(trackBar1.Value); backgroundWorker1.RunWorkerAsync(filter); break; case 24: filter = new Closing(trackBar1.Value); backgroundWorker1.RunWorkerAsync(filter); break; case 25: filter = new Grad(trackBar1.Value); backgroundWorker1.RunWorkerAsync(filter); break; case 26: filter = new TopHat(trackBar1.Value); backgroundWorker1.RunWorkerAsync(filter); break; case 27: filter = new BlackHat(trackBar1.Value); backgroundWorker1.RunWorkerAsync(filter); break; } }
private void сужениеToolStripMenuItem_Click(object sender, EventArgs e) { Filters filter = new Erosion(StructElem); backgroundWorker1.RunWorkerAsync(filter); }