Saturation adjusting of HSL color space
Inheritance: IFilter, IInPlaceFilter
        private void cBFilters_SelectedIndexChanged(object sender, EventArgs e)
        {
            Bitmap pictureTransform = (Bitmap)pbChoose.Image;
                if ((string)cBFilters.SelectedItem == "HSL_Filter")
                {
                    AForge.Imaging.Filters.SaturationCorrection filter = new SaturationCorrection(0.1);
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                if ((string)cBFilters.SelectedItem == "Mediana")
                {
                    AForge.Imaging.Filters.Median filter = new Median();
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                /*if ((string)cBFilters.SelectedItem == "Fourier_Transformation")
                {
                 Complex[] dst = new Complex[n];

                    AForge.Math.FourierTransform filter = AForge.Math.FourierTransform.DFT();// .FromBitmap(pictureTransform);
                    Bitmap newImage = filter.Apply();
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }*/

                if ((string)cBFilters.SelectedItem == "Binarization")
                {
                    pictureTransform = Grayscale.CommonAlgorithms.BT709.Apply(pictureTransform);
                    Threshold threshold = new Threshold(127);
                    threshold.ApplyInPlace(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = pictureTransform;
                }

                if ((string)cBFilters.SelectedItem == "Grayscale")
                {
                    AForge.Imaging.Filters.Grayscale filter = new AForge.Imaging.Filters.Grayscale(0.2125, 0.7154, 0.0721);
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                if ((string)cBFilters.SelectedItem == "FillHoles")
                {

                    pictureTransform = Grayscale.CommonAlgorithms.BT709.Apply(pictureTransform);
                    Threshold threshold = new Threshold(127);
                    threshold.ApplyInPlace(pictureTransform);
                    AForge.Imaging.Filters.FillHoles filter = new AForge.Imaging.Filters.FillHoles();
                    filter.MaxHoleHeight = 5;
                    filter.MaxHoleWidth = 15;
                    filter.CoupledSizeFiltering = false;
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                if ((string)cBFilters.SelectedItem == "Opening")
                {
                    AForge.Imaging.Filters.Opening filter = new AForge.Imaging.Filters.Opening();
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                if ((string)cBFilters.SelectedItem == "Closing")
                {
                    AForge.Imaging.Filters.Closing filter = new AForge.Imaging.Filters.Closing();
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                if ((string)cBFilters.SelectedItem == "Erosion")
                {
                    AForge.Imaging.Filters.Erosion filter = new AForge.Imaging.Filters.Erosion();
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                if ((string)cBFilters.SelectedItem == "Dilatation")
                {
                    AForge.Imaging.Filters.Dilatation filter = new AForge.Imaging.Filters.Dilatation();
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }

                if ((string)cBFilters.SelectedItem == "Edges")
                {
                    AForge.Imaging.Filters.Edges filter = new AForge.Imaging.Filters.Edges();
                    Bitmap newImage = filter.Apply(pictureTransform);
                    pbChoose.SizeMode = PictureBoxSizeMode.CenterImage;
                    pBNew.Image = newImage;
                }
        }
Exemple #2
0
 private static Bitmap changeHSL(Bitmap bmp, int h, double s, double l, bool keepBW, bool keepGray, int grayTolerance)
 {
     s = Math.Round(s / 100, 2);
     l = Math.Round(l / 100, 2);
     HueModifierRelative hue = new HueModifierRelative(h, keepBW);
     SaturationCorrection saturation = new SaturationCorrection(s, keepBW, keepGray, grayTolerance);
     BrightnessCorrection bright = new BrightnessCorrection(l, keepBW, keepGray, grayTolerance);
     hue.ApplyInPlace(bmp);
     saturation.ApplyInPlace(bmp);
     bright.ApplyInPlace(bmp);
     return bmp;
 }
Exemple #3
0
        public static bool ColorCorrections(string fileName, int brightness, int contrast, double gamma, int hue, float saturation)
        {
            if (String.IsNullOrEmpty(fileName)) throw new ArgumentNullException("fileName");

            bool result = false;

            using (var ms = new MemoryStream(File.ReadAllBytes(fileName)))
            {
                using (Bitmap bmp = new Bitmap(ms))
                {
                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-255, +255] default 10
                    if (brightness >= -255 && brightness != 0 && brightness <= 255)
                    {
                        BrightnessCorrection filter = new BrightnessCorrection(brightness);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-127, +127] default 10
                    if (contrast >= -127 && contrast != 0 && contrast <= 127)
                    {
                        ContrastCorrection filter = new ContrastCorrection(contrast);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 8 bpp grayscale and 24 bpp color images for processing, value [0.1, 5.0] default 1.0
                    if (gamma >= 0.1D && gamma != 1D && gamma <= 5D)
                    {
                        GammaCorrection filter = new GammaCorrection(gamma);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-180, +180] default 0
                    if (hue >= -180 && hue != 0 && hue <= 180)
                    {
                        HueModifier filter = new HueModifier(hue);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 24 and 32 bpp color images for processing, value specified percentage [-1, +1] default 0.1
                    if (saturation >= -100f && saturation != 0f && saturation <= 100f)
                    {
                        SaturationCorrection filter = new SaturationCorrection(saturation / 100);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    bmp.Save(fileName);
                }
            }

            return result;
        }
Exemple #4
0
        private void Saturation_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            SaturationLabel.Content = (int)(Saturation.Value * 100);
            saturation = (float)Saturation.Value;

            if (mainPhoto != null)
            {
                sc = new SaturationCorrection(saturation);
                System.Drawing.Bitmap tmp = sc.Apply((System.Drawing.Bitmap)mainPhoto.Clone());
                //BitmapImage tmpBmpIs = ToBitmapImage(tmp);

                Photography.Source = ToBitmapImage(tmp);

                UpdateHistograms(tmp);
                UpdateChannelPreviews(tmp);
            }
        }
Exemple #5
0
        public static BitmapSource ColorCorrections(BitmapSource source, int brightness, int contrast, double gamma, int hue, float saturation)
        {
            if (source == null) throw new ArgumentNullException("source");

            BitmapSource output = null;

            if (source.Format == PixelFormats.Bgr32 && gamma != 1D)
            {
                source = new FormatConvertedBitmap(source, PixelFormats.Bgr24, null, 0);
            }

            using (Bitmap bmp = Convert(source))
            {
                int bpp = source.Format.BitsPerPixel;

                if (bpp == 8 || bpp == 24 || bpp == 32)
                {
                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-255, +255] default 10
                    if (brightness >= -255 && brightness != 0 && brightness <= 255)
                    {
                        BrightnessCorrection filter = new BrightnessCorrection(brightness);
                        filter.ApplyInPlace(bmp);
                    }

                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-127, +127] default 10
                    if (contrast >= -127 && contrast != 0 && contrast <= 127)
                    {
                        ContrastCorrection filter = new ContrastCorrection(contrast);
                        filter.ApplyInPlace(bmp);
                    }
                }

                if (bpp == 8 || bpp == 24)
                {
                    //The filter accepts 8 bpp grayscale and 24 bpp color images for processing, value [0.1, 5.0] default 1.0
                    if (gamma >= 0.1D && gamma != 1D && gamma <= 5D)
                    {
                        GammaCorrection filter = new GammaCorrection(gamma);
                        filter.ApplyInPlace(bmp);
                    }
                }

                if (bpp == 8 || bpp == 24 || bpp == 32)
                {
                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-180, +180] default 0
                    if (hue >= -180 && hue != 0 && hue <= 180)
                    {
                        HueModifier filter = new HueModifier(hue);
                        filter.ApplyInPlace(bmp);
                    }
                }

                if (bpp == 24 || bpp == 32)
                {
                    //The filter accepts 24 and 32 bpp color images for processing, value specified percentage [-1, +1] default 0.1
                    if (saturation >= -100f && saturation != 0f && saturation <= 100f)
                    {
                        SaturationCorrection filter = new SaturationCorrection(saturation / 100);
                        filter.ApplyInPlace(bmp);
                    }
                }

                output = Convert(bmp);
            }

            return CloneImage(output);
        }