Beispiel #1
0
        private void applyFilterButton_Click(object sender, EventArgs e)
        {
            //pictureBox1.Image = nw.returnGraytoImage();

            if (filterchosen != "" && !NoImage)
            {
                if (filterchosen.Contains("Sobel"))
                {
                    Bitmap       imgtmp = ImageProcessor.CopyImage(img.ViewedImage);
                    PreviewImage tmp    = new PreviewImage(imgtmp);

                    img.filterImage(sobelv);
                    //     tmp.filterImage(sobelh);
                    //  img = img + tmp;
                }
                else if (filterchosen.Contains("Robert Cross"))
                {
                    Bitmap       imgtmp = ImageProcessor.CopyImage(img.ViewedImage);
                    PreviewImage tmp    = new PreviewImage(imgtmp);
                    img.filterImage(RobertCrossH);
                    tmp.filterImage(RobertCrossV);
                    img = img + tmp;
                }
                else if (filterchosen.Contains("UnSharpen"))
                {
                    Bitmap       imgtmp  = ImageProcessor.CopyImage(img.ViewedImage);
                    PreviewImage tmp     = new PreviewImage(imgtmp);
                    Bitmap       imgtmp2 = ImageProcessor.CopyImage(img.ViewedImage);
                    PreviewImage tmp2    = new PreviewImage(imgtmp2);
                    tmp.filterImage(blur);
                    tmp2 = tmp2 - tmp;
                    int k = 5;
                    if (!filterchosen.Contains("HighBoost"))
                    {
                        k = 1;
                    }
                    for (int i = 0; i < k; i++)
                    {
                        img = img + tmp2;
                    }
                }
                else if (filterchosen == "Average Noise Reduction")
                {
                    List <PreviewImage> noisyImages = new List <PreviewImage>();

                    ///fill list

                    Bitmap newImage = ImageProcessor.CopyImage(img.ViewedImage);

                    for (int r = 0; r < img.ViewedImage.Width; r++)
                    {
                        for (int c = 0; c < img.ViewedImage.Height; c++)
                        {
                            int redTotal = 0, greenTotal = 0, blueTotal = 0;

                            for (int i = 0; i < noisyImages.Count; i++)
                            {
                                Color color = noisyImages[i].ViewedImage.GetPixel(r, c);
                                redTotal   += color.R;
                                greenTotal += color.G;
                                blueTotal  += color.B;
                            }

                            redTotal   /= noisyImages.Count;
                            greenTotal /= noisyImages.Count;
                            blueTotal  /= noisyImages.Count;

                            newImage.SetPixel(r, c, Color.FromArgb(redTotal, greenTotal, blueTotal));
                        }
                    }

                    PreviewImage newPrev = new PreviewImage(newImage, img.isColorised);
                    img.ViewedImage = newPrev.ViewedImage;
                    img.Mat         = newPrev.Mat;
                    img.GetViewedImage();
                    img.previewStages.Add(new PreviewState(img.stages, avgNoiseReduction, img.OriginalImage, img.ViewedImage, img.ColorisedImage, img.GrayscaleImage, img.MatOrigin, img.isColorised, img.brightness, img.contrast, img.saturation));
                }
                else if (filterchosen.Contains("Prewitt"))
                {
                    Bitmap       imgtmp = ImageProcessor.CopyImage(img.ViewedImage);
                    PreviewImage tmp    = new PreviewImage(imgtmp);
                    img.filterImage(Pewitt);
                    tmp.filterImage(Pewitt2);
                    img = img + tmp;
                }



                else if (filterchosen.Contains("Cartoon"))
                {
                    Bitmap imgtmp  = ImageProcessor.CopyImage(img.ViewedImage);
                    Bitmap imgtmp2 = ImageProcessor.CopyImage(img.ViewedImage);

                    PreviewImage tmp = new PreviewImage(imgtmp);

                    PreviewImage tmp2 = new PreviewImage(imgtmp2);
                    for (int i = 0; i < 2; i++)
                    {
                        tmp.filterImage(Median);
                        tmp2.filterImage(Median);
                    }

                    tmp.filterImage(sobelh);

                    tmp2.filterImage(sobelv);
                    tmp = tmp + tmp2;
                    for (int i = 0; i < 6; i++)
                    {
                        img.filterImage(blur);
                    }
                    img = img - tmp;
                    ViewImages();
                }
                else
                {
                    if (filterchosen == "Salt and Pepper")
                    {
                        saltAndPepper.randomUpdateFilter(img.ViewedImage.Width, img.ViewedImage.Height, 0, 256, false);
                    }
                    if (filterchosen == "Gaussian Noise")
                    {
                        gaussianNoise.randomUpdateFilter(img.ViewedImage.Width, img.ViewedImage.Height, 0, (0.1f * 0.5f), true);
                    }

                    img.filterImage(Filters[filterchosen]);
                }

                ViewImages();
            }
        }