Esempio n. 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = openFileDialog1;

            dialog.Title  = "Open Image";
            dialog.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                Bitmap img3 = (Bitmap)Image.FromFile(dialog.FileName);
                comparedImage = new PreviewImage((Bitmap)img3);
                if (img3.Width == img.ViewedImage.Width && img3.Height == img.ViewedImage.Height)
                {
                    Bitmap       imgtmp  = ImageProcessor.CopyImage(img3);
                    PreviewImage tmp     = new PreviewImage(imgtmp);
                    Bitmap       imgtmp3 = ImageProcessor.CopyImage(img3);
                    PreviewImage tmp3    = new PreviewImage(imgtmp3);
                    Bitmap       imgtmp2 = ImageProcessor.CopyImage(img.ViewedImage);
                    PreviewImage tmp2    = new PreviewImage(imgtmp2);
                    tmp.filterImage(blur);
                    tmp2.filterImage(blur);
                    tmp3 = tmp3 - tmp;
                    img  = tmp3 + tmp2;
                    ViewImages();
                }
            }
        }
Esempio n. 2
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();
            }
        }