예제 #1
0
        private void button1_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)
                {
                    img.Difference = true;
                    img            = img - comparedImage;
                    img.RangeDifference();
                    img.Difference = false;
                    ViewImages();
                }
            }
        }
예제 #2
0
        public Bitmap updateImageContrast(int contrastValue)
        {
            contrast = contrastValue;
            Bitmap contrastedImage = ImageProcessor.CopyImage(ColorisedImage);
            double factor          = (double)(259 * (contrastValue + 255)) / (double)(255 * (259 - contrastValue));

            for (int r = 0; r < contrastedImage.Width; r++)
            {
                for (int c = 0; c < contrastedImage.Height; c++)
                {
                    double red   = contrastedImage.GetPixel(r, c).R;
                    double green = contrastedImage.GetPixel(r, c).G;
                    double blue  = contrastedImage.GetPixel(r, c).B;
                    red   = (int)(factor * (red - 128) + 128);
                    green = (int)(factor * (green - 128) + 128);
                    blue  = (int)(factor * (blue - 128) + 128);
                    ImageProcessor.RangeColors(ref red, ref green, ref blue);
                    contrastedImage.SetPixel(r, c, Color.FromArgb(contrastedImage.GetPixel(r, c).A, (int)red, (int)green, (int)blue));
                }
            }

            PreviewImage contrastedColoredImage = new PreviewImage(contrastedImage, true);
            PreviewImage contrastedGreyImage    = new PreviewImage(contrastedImage, false);

            if (isColorised)
            {
                Mat = contrastedColoredImage.Mat;
                GetViewedImage();
                previewStages.Add(new PreviewState(stages, null, OriginalImage, ViewedImage, ColorisedImage, GrayscaleImage, CopyMat(), isColorised, brightness, contrast, saturation));
            }
            else
            {
                Mat = contrastedGreyImage.Mat;
                GetViewedImage();
                previewStages.Add(new PreviewState(stages, null, OriginalImage, ViewedImage, ColorisedImage, GrayscaleImage, CopyMat(), isColorised, brightness, contrast, saturation));
            }

            return(contrastedImage);
        }
예제 #3
0
        public Bitmap updateImageSaturation(int saturation)
        {
            this.saturation = saturation;
            Bitmap saturatedImage = ImageProcessor.CopyImage(ColorisedImage);

            for (int r = 0; r < saturatedImage.Width; r++)
            {
                for (int c = 0; c < saturatedImage.Height; c++)
                {
                    int red   = saturatedImage.GetPixel(r, c).R;
                    int green = saturatedImage.GetPixel(r, c).G;
                    int blue  = saturatedImage.GetPixel(r, c).B;

                    double[] hsv = ImageProcessor.RGBToHSV(Color.FromArgb(red, green, blue));
                    hsv[1] += Math.Min(hsv[1], hsv[1] + saturation);
                    Color color = ImageProcessor.HSVToRGB(hsv);
                    saturatedImage.SetPixel(r, c, color);
                }
            }

            PreviewImage saturatedColoredImage = new PreviewImage(saturatedImage, true);
            PreviewImage saturatedGreyImage    = new PreviewImage(saturatedImage, false);

            if (isColorised)
            {
                Mat = saturatedColoredImage.Mat;
                GetViewedImage();
                previewStages.Add(new PreviewState(stages, null, OriginalImage, ViewedImage, ColorisedImage, GrayscaleImage, CopyMat(), isColorised, brightness, contrast, saturation));
            }
            else
            {
                Mat = saturatedGreyImage.Mat;
                GetViewedImage();
                previewStages.Add(new PreviewState(stages, null, OriginalImage, ViewedImage, ColorisedImage, GrayscaleImage, CopyMat(), isColorised, brightness, contrast, saturation));
            }

            return(saturatedImage);
        }
예제 #4
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();
            }
        }