예제 #1
0
        private void CorrectLevel(int MinLevel, int MaxLevel)
        {
            LevelsLinear filter = new LevelsLinear();

            filter.Input = new IntRange(MinLevel, MaxLevel);
            filter.ApplyInPlace(_recogimg);
        }
예제 #2
0
        public void WriteResults(Bitmap frame, TimeAggregator timeAggregator)
        {
            // Reduce brightness of incoming image to approximately 20% before we write on it.
            LevelsLinear filter = new LevelsLinear();

            filter.OutRed   = new IntRange(0, 50);
            filter.OutGreen = new IntRange(0, 50);
            filter.OutBlue  = new IntRange(0, 50);
            filter.ApplyInPlace(frame);

            var maxRows = Math.Min(20, timeAggregator.Times.Count()) + 3;

            frame.WriteLine($"Average (drop high & low): {timeAggregator.AverageDropHighLow.ToSecondsString()}", 0, maxRows, resultsDefaultBrush);
            frame.WriteLine($"Mean: {timeAggregator.Mean.ToSecondsString()}", 1, maxRows, resultsDefaultBrush);
            int currentIndex = 0;
            int minIndex     = timeAggregator.Times.MinIndex();
            int maxIndex     = timeAggregator.Times.MaxIndex();

            foreach (var time in timeAggregator.Times)
            {
                var brush = currentIndex == minIndex ? resultsBestTimeBrush :
                            currentIndex == maxIndex ? resultsWorstTimeBrush : resultsDefaultBrush;
                frame.WriteLine($"{currentIndex + 1}. {time.ToSecondsString()}", 3 + currentIndex, maxRows, brush);
                ++currentIndex;
            }
        }
예제 #3
0
 public LevelsLinearFilter()
 {
     levelsLinear         = new LevelsLinear();
     levelsLinear.InRed   = new IntRange(30, 230);
     levelsLinear.InGreen = new IntRange(50, 240);
     levelsLinear.InBlue  = new IntRange(10, 210);
 }
예제 #4
0
 private static Bitmap CreateGrayscale(Bitmap image)
 {
     
     const int size = 512;
     float scale = Math.Min(size / (float)image.Width, size / (float)image.Height);
     ResizeBicubic resize = new ResizeBicubic((int)(image.Width*scale), (int)(image.Height*scale));
     
     ImageStatistics stat = new ImageStatistics( image );
     LevelsLinear levelsLinear = new LevelsLinear
     {
         Output = new IntRange(0, 255),
         InRed = stat.Red.GetRange(.95),
         InBlue = stat.Blue.GetRange(.95),
         InGreen = stat.Green.GetRange(.95)
     };
     SaturationCorrection sc = new SaturationCorrection(-1);
     Bitmap square = new Bitmap(size, size);
     using(Bitmap resized = resize.Apply(sc.Apply(levelsLinear.Apply(image)).MakeGrayscale()))
     using (Graphics g = Graphics.FromImage(square))
     {
         g.DrawImage(resized, new Point((size-resized.Width) / 2 ,0));
     }
     
     return square;
 }
예제 #5
0
        // On Filters->Levels Linear Correction
        private void rgbLinearFiltersItem_Click(object sender, System.EventArgs e)
        {
            LevelsLinear filter = new LevelsLinear( );

            filter.InRed   = new IntRange(30, 230);
            filter.InGreen = new IntRange(50, 240);
            filter.InBlue  = new IntRange(10, 210);

            ApplyFilter(filter);
            rgbLinearFiltersItem.Checked = true;
        }
예제 #6
0
        private void ProcessSingleImage(Bitmap source)
        {
            ImageStatistics stats        = new ImageStatistics(source);
            LevelsLinear    levelsLinear = new LevelsLinear {
                InRed   = stats.Red.GetRange(0.87),
                InGreen = stats.Green.GetRange(0.87),
                InBlue  = stats.Blue.GetRange(0.87)
            };

            levelsLinear.ApplyInPlace(source);
        }
예제 #7
0
        /*TEMP
         * // On Filters->Difference edge detector
         * void differenceEdgesFiltersItem_Click(Base control)
         * {
         *  // save original image
         *  Bitmap originalImage = sourceImage;
         *  // get grayscale image
         *  sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
         *  // apply edge filter
         *  ApplyFilter(new DifferenceEdgeDetector());
         *  // delete grayscale image and restore original
         *  sourceImage.Dispose();
         *  sourceImage = originalImage;
         *
         *  differenceEdgesFiltersItem.IsChecked = true;
         * }
         *
         *
         * // On Filters->Homogenity edge detector
         * void homogenityEdgesFiltersItem_Click(Base control)
         * {
         *  // save original image
         *  Bitmap originalImage = sourceImage;
         *  // get grayscale image
         *  sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
         *  // apply edge filter
         *  ApplyFilter(new HomogenityEdgeDetector());
         *  // delete grayscale image and restore original
         *  sourceImage.Dispose();
         *  sourceImage = originalImage;
         *
         *  homogenityEdgesFiltersItem.IsChecked = true;
         * }
         *
         *
         * // On Filters->Sobel edge detector
         * void sobelEdgesFiltersItem_Click(Base control)
         * {
         *  // save original image
         *  Bitmap originalImage = sourceImage;
         *  // get grayscale image
         *  sourceImage = Grayscale.CommonAlgorithms.RMY.Apply(sourceImage);
         *  // apply edge filter
         *  ApplyFilter(new SobelEdgeDetector());
         *  // delete grayscale image and restore original
         *  sourceImage.Dispose();
         *  sourceImage = originalImage;
         *
         *  sobelEdgesFiltersItem.IsChecked = true;
         * }*/


        // On Filters->Levels Linear Correction
        void rgbLinearFiltersItem_Click(Base control)
        {
            LevelsLinear filter = new LevelsLinear();

            filter.InRed   = new IntRange(30, 230);
            filter.InGreen = new IntRange(50, 240);
            filter.InBlue  = new IntRange(10, 210);

            ApplyFilter(filter);
            rgbLinearFiltersItem.IsChecked = true;
        }
예제 #8
0
        private void levelsLinearCorrectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            UncheckAllMenuItems();
            LevelsLinear filter = new LevelsLinear();

            filter.InRed = new IntRange(30, 230);
            filter.InGreen = new IntRange(50, 240);
            filter.InBlue = new IntRange(10, 210);

            ApplyFilter(filter);
            levelsLinearCorrectionToolStripMenuItem.Checked = true;
        }
예제 #9
0
        private void sbColorRemap_ValueChanged(object sender, EventArgs e)
        {
            Bitmap       img    = new Bitmap(image);
            LevelsLinear filter = new LevelsLinear();

            // set ranges
            filter.InRed   = new IntRange(sbColorRemap.Value, 300);
            filter.InGreen = new IntRange(sbColorRemap.Value, 300);
            filter.InBlue  = new IntRange(sbColorRemap.Value, 300);
            // apply the filter
            filter.ApplyInPlace(img);
            pictureBox2.Image = img;
        }
예제 #10
0
        private Bitmap ProcessSingleImage(Bitmap _src)
        {
            ImageStatistics stats = new ImageStatistics(_src);

            LevelsLinear levelsLinear = new LevelsLinear();

            levelsLinear.InRed   = stats.Red.GetRange(0.87);
            levelsLinear.InGreen = stats.Green.GetRange(0.87);
            levelsLinear.InBlue  = stats.Blue.GetRange(0.87);

            levelsLinear.ApplyInPlace(_src);

            return(_src);
        }
예제 #11
0
        // On Filters->Levels Linear Correction
        //水平线性矫正
        private void rgbLinearFiltersItem_Click(object sender, System.EventArgs e)
        {
            LevelsLinear filter = new LevelsLinear();

            /*
             * 该滤波器通过将指定信道的输入范围映射到输出范围来执行对RGB信道的线性校正。
             * 它类似于颜色映射,但是重新映射是线性的。
             */
            filter.InRed   = new IntRange(30, 230);
            filter.InGreen = new IntRange(50, 240);
            filter.InBlue  = new IntRange(10, 210);

            ApplyFilter(filter);
            rgbLinearFiltersItem.Checked = true;
        }
예제 #12
0
        public static Image ApplyRangeLevels(int minimum, int maximum, Image inputImage)
        {
            // create filter
            LevelsLinear filter = new LevelsLinear()
            { /* set ranges*/
                InRed   = new AForge.IntRange(minimum, maximum),
                InGreen = new AForge.IntRange(minimum, maximum),
                InBlue  = new AForge.IntRange(minimum, maximum)
            };

            // apply the filter
            using (Bitmap filteredImage = (Bitmap)inputImage.Clone())
            {
                filter.ApplyInPlace(filteredImage);
                return((Bitmap)filteredImage.Clone());
            }
        }
 public PreProcess(UISettings ui, FileData file)
 {
     try {
         ExtendFileData(file);
         BitmapOriginal  = (ui.WorkDirectory + "\\" + FileName).FileTo24bbpRgb(ResizeRatio: ui.ResizeValue, FrameCrop: ui.CropValue, ImageZoom: 1, RotateDegree: ui.RotateDegree);
         UnmanagedMarkup = UnmanagedImage.FromManagedImage(BitmapOriginal);
         ImageStatistics stats    = null;
         Threshold       AFbinary = new Threshold(1);
         Grayscale       AFgray   = new Grayscale(0.1, 0.7, 0.2);
         if (ui.ExcludeColorSwitch && ui.ExcludeColorRadius > 0)
         {
             System.Windows.Media.Color excolor   = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(ui.ExcludeColorHex);
             EuclideanColorFiltering    AFexcolor = new EuclideanColorFiltering(new RGB(excolor.R, excolor.G, excolor.B), (short)ui.ExcludeColorRadius);
             UnmanagedExclude = AFbinary.Apply(AFgray.Apply(AFexcolor.Apply(UnmanagedMarkup)));
         }
         else
         {
             UnmanagedExclude = UnmanagedImage.Create(UnmanagedMarkup.Width, UnmanagedMarkup.Height, PixelFormat.Format8bppIndexed);
         }
         if (ui.WhiteBalanceSwitch || ui.BlackBalanceSwitch)                 // need to apply auto white/black balance
         {
             Invert AFinvert = new Invert();
             stats = new ImageStatistics(UnmanagedMarkup, AFinvert.Apply(UnmanagedExclude));
             int          lowend       = (ui.BlackBalanceSwitch) ? (int)Math.Round(0.333d * (stats.RedWithoutBlack.Center2QuantileValue(ui.BlackBalance) + stats.GreenWithoutBlack.Center2QuantileValue(ui.BlackBalance) + stats.BlueWithoutBlack.Center2QuantileValue(ui.BlackBalance))):0;
             LevelsLinear levelsLinear = new LevelsLinear {
                 InRed   = new IntRange(lowend, (ui.WhiteBalanceSwitch) ? stats.RedWithoutBlack.Center2QuantileValue(ui.WhiteBalance) : 255),
                 InGreen = new IntRange(lowend, (ui.WhiteBalanceSwitch) ? stats.GreenWithoutBlack.Center2QuantileValue(ui.WhiteBalance) : 255),
                 InBlue  = new IntRange(lowend, (ui.WhiteBalanceSwitch) ? stats.BlueWithoutBlack.Center2QuantileValue(ui.WhiteBalance) : 255),
             };
             //LevelsLinear levelsLinear = new LevelsLinear {
             //	InRed=new IntRange((ui.BlackBalanceSwitch)?stats.RedWithoutBlack.Center2QuantileValue(ui.BlackBalance):0, (ui.WhiteBalanceSwitch)?stats.RedWithoutBlack.Center2QuantileValue(ui.WhiteBalance):255),
             //	InGreen=new IntRange((ui.BlackBalanceSwitch)?stats.GreenWithoutBlack.Center2QuantileValue(ui.BlackBalance):0, (ui.WhiteBalanceSwitch)?stats.GreenWithoutBlack.Center2QuantileValue(ui.WhiteBalance):255),
             //	InBlue=new IntRange((ui.BlackBalanceSwitch)?stats.BlueWithoutBlack.Center2QuantileValue(ui.BlackBalance):0, (ui.WhiteBalanceSwitch)?stats.BlueWithoutBlack.Center2QuantileValue(ui.WhiteBalance):255),
             //};
             levelsLinear.ApplyInPlace(UnmanagedMarkup);
         }
         if (ui.GaussianBlurSwitch && ui.GaussianBlur != 0)                                           // Gaussian Blur and Darken
         {
             GaussianBlur AFgblur     = new GaussianBlur(11.0, Math.Max(ui.GaussianBlur, 0) * 2 + 1); // Gaussian Blur sigma = 8.0 kernel size = 7
             Intersect    AFintersect = new Intersect(AFgblur.Apply(UnmanagedMarkup));
             UnmanagedMarkup = AFintersect.Apply(UnmanagedMarkup);
         }
         UnmanagedGray = AFgray.Apply(UnmanagedMarkup);               // directly turn into gray
     } catch { throw new Exception("Error Occured During PreProcessing"); }
 }
예제 #14
0
        private void RunLevels()
        {
            BitmapType = mFilter.BitmapTypes.None;

            Effect = new LevelsLinear();

            Effect.InRed  = new Accord.IntRange((int)RedIn.T0, (int)RedIn.T1);
            Effect.OutRed = new Accord.IntRange((int)RedOut.T0, (int)RedOut.T1);

            Effect.InGreen  = new Accord.IntRange((int)GreenIn.T0, (int)GreenIn.T1);
            Effect.OutGreen = new Accord.IntRange((int)GreenOut.T0, (int)GreenOut.T1);

            Effect.InBlue  = new Accord.IntRange((int)BlueIn.T0, (int)BlueIn.T1);
            Effect.OutBlue = new Accord.IntRange((int)BlueOut.T0, (int)BlueOut.T1);

            Effect.InGray  = new Accord.IntRange((int)GrayIn.T0, (int)GrayIn.T1);
            Effect.OutGray = new Accord.IntRange((int)GrayOut.T0, (int)GrayOut.T1);

            filter = Effect;
        }
예제 #15
0
        private Bitmap ProcessSingleImage(Bitmap _src)
        {
            Bitmap img = (_src.PixelFormat == PixelFormat.Format24bppRgb) ? _src : CloneTo24bpp(_src);

            ImageStatistics stats = new ImageStatistics(img);

            LevelsLinear levelsLinear = new LevelsLinear();

            levelsLinear.InRed   = stats.Red.GetRange(0.87);
            levelsLinear.InGreen = stats.Green.GetRange(0.87);
            levelsLinear.InBlue  = stats.Blue.GetRange(0.87);

            levelsLinear.ApplyInPlace(img);

            if (_src.PixelFormat != PixelFormat.Format24bppRgb)
            {
                Graphics g = Graphics.FromImage(_src);
                g.DrawImageUnscaled(img, 0, 0);
                img.Dispose();
            }

            return(_src);
        }
예제 #16
0
        private Bitmap AddFilter(Bitmap bitmap)
        {
            switch (filterNumber)
            {
            case Filters.BrightnessCorrection:
                return(ApplyFilter(bitmap, new BrightnessCorrection()));

            case Filters.ColorFiltering:
                return(ApplyFilter(bitmap, new ColorFiltering(new IntRange(25, 230), new IntRange(25, 230), new IntRange(25, 230))));

            case Filters.ContrastCorrection:
                return(ApplyFilter(bitmap, new ContrastCorrection()));

            case Filters.DifferenceEdgeDetector:
                bitmap = Grayscale.CommonAlgorithms.RMY.Apply(bitmap);
                return(ApplyFilter(bitmap, new DifferenceEdgeDetector()));

            case Filters.FloydSteinbergDithering:
                bitmap = Grayscale.CommonAlgorithms.RMY.Apply(bitmap);
                return(ApplyFilter(bitmap, new FloydSteinbergDithering()));

            case Filters.Grayscale:
                return(ApplyFilter(bitmap, Grayscale.CommonAlgorithms.BT709));

            case Filters.HomogenityEdgeDetector:
                bitmap = Grayscale.CommonAlgorithms.RMY.Apply(bitmap);
                return(ApplyFilter(bitmap, new HomogenityEdgeDetector()));

            case Filters.HSLFiltering:
                return(ApplyFilter(bitmap, new HSLFiltering(new IntRange(330, 30), new Range(0, 1), new Range(0, 1))));

            case Filters.HueModifier:
                return(ApplyFilter(bitmap, new HueModifier(50)));

            case Filters.Jitter:
                return(ApplyFilter(bitmap, new Jitter()));

            case Filters.LevelsLinear:
                LevelsLinear lfilter = new LevelsLinear();
                lfilter.InRed   = new IntRange(30, 230);
                lfilter.InGreen = new IntRange(50, 240);
                lfilter.InBlue  = new IntRange(10, 210);
                return(ApplyFilter(bitmap, lfilter));

            case Filters.OrderedDithering:
                bitmap = Grayscale.CommonAlgorithms.RMY.Apply(bitmap);
                return(ApplyFilter(bitmap, new OrderedDithering()));

            case Filters.RotateChannels:
                return(ApplyFilter(bitmap, new RotateChannels()));

            case Filters.SaturationCorrection:
                return(ApplyFilter(bitmap, new SaturationCorrection(0.15f)));

            case Filters.Sepia:
                return(ApplyFilter(bitmap, new Sepia()));

            case Filters.SobelEdgeDetector:
                bitmap = Grayscale.CommonAlgorithms.RMY.Apply(bitmap);
                return(ApplyFilter(bitmap, new SobelEdgeDetector()));

            case Filters.Threshold:
                bitmap = Grayscale.CommonAlgorithms.RMY.Apply(bitmap);
                return(ApplyFilter(bitmap, new Threshold()));

            case Filters.YCbCrFiltering:
                return(ApplyFilter(bitmap, new YCbCrFiltering(new Range(0.2f, 0.9f), new Range(-0.3f, 0.3f), new Range(-0.3f, 0.3f))));

            case Filters.YCbCrLinear:
                YCbCrLinear filter = new YCbCrLinear();
                filter.InCb = new Range(-0.3f, 0.3f);
                return(ApplyFilter(bitmap, filter));

            default:
                return(bitmap);
            }
        }
예제 #17
0
 public MinMaxLinearStretch()
 {
     levelsLinear = new LevelsLinear();
 }
예제 #18
0
        public Bitmap ProcessImage(ImageProcessorSettings settings)
        {
            Bitmap output = Image.Clone() as Bitmap;

            if (settings.RemoveBorder > 0)
            {
                int x = settings.RemoveBorder;
                output = new Crop(new Rectangle(x, x, Image.Width - (2 * x), Image.Height - (2 * x))).Apply(Image);
            }

            if (settings.RemovePixelNoise > 0)
            {
                for (int i = 0; i < settings.RemovePixelNoise; i++)
                {
                    // Use a copy for iteration
                    Bitmap bitmap = new Bitmap(output);

                    for (int j = 1; j < (output.Height - 1); j++)
                    {
                        for (int k = 1; k < (output.Width - 1); k++)
                        {
                            if (output.GetPixel(k, j).GetBrightness() < 0.5)
                            {
                                // Top left
                                float tl = output.GetPixel(k - 1, j).GetBrightness();
                                // Top right
                                float tr = output.GetPixel(k + 1, j).GetBrightness();
                                // Bottom left
                                float bl = output.GetPixel(k, j - 1).GetBrightness();
                                // Bottom right
                                float br = output.GetPixel(k, j + 1).GetBrightness();

                                // Test the edges
                                if (tl > 0.5 && tr > 0.5)
                                {
                                    bitmap.SetPixel(k, j, Color.White);
                                }
                                if (bl > 0.5 && br > 0.5)
                                {
                                    bitmap.SetPixel(k, j, Color.White);
                                }
                            }
                        }
                    }
                    output = bitmap;
                }
            }
            if (settings.LinearizeColors)
            {
                ImageStatistics statistics = new ImageStatistics(output);
                output = new LevelsLinear {
                    InRed   = new Range(statistics.Red.Min, statistics.Red.Max),
                    InGreen = new Range(statistics.Green.Min, statistics.Green.Max),
                    InBlue  = new Range(statistics.Blue.Min, statistics.Blue.Max)
                }.Apply(output);
            }
            if (settings.InvertColors)
            {
                output = new Invert().Apply(output);
            }
            if (settings.ImageBlur)
            {
                output = new Blur().Apply(output);
            }
            if (settings.BrightnessThreshold > 0)
            {
                // Brightness threshold is in percent..
                decimal threshold = (decimal)settings.BrightnessThreshold / 100M;
                output = new Threshold(Convert.ToByte((decimal)(threshold * 255M)), 255).Apply(output);
            }

            return(output);
        }
예제 #19
0
        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="image">Source image data.</param>
        /// <param name="rect">Image rectangle for processing by the filter.</param>
        ///
        protected override unsafe void ProcessFilter( UnmanagedImage image, Rectangle rect )
        {
            int pixelSize = Image.GetPixelFormatSize( image.PixelFormat ) / 8;

            int startX = rect.Left;
            int startY = rect.Top;
            int stopX  = startX + rect.Width;
            int stopY  = startY + rect.Height;
            int stride = image.Stride;
            int offset = stride - rect.Width * pixelSize;

            // levels linear correction filter is going to be used on STEP 2
            LevelsLinear levelsLinear = new LevelsLinear( );

            // STEP 1 - search for min and max pixel values
            byte* ptr = (byte*) image.ImageData.ToPointer( );

            // check image format
            if ( image.PixelFormat == PixelFormat.Format8bppIndexed )
            {
                // allign pointer to the first pixel to process
                ptr += ( startY * stride + startX );

                byte min = 255;
                byte max = 0;

                for ( int y = startY; y < stopY; y++ )
                {
                    for ( int x = startX; x < stopX; x++, ptr++ )
                    {
                        byte value = *ptr;

                        if ( value < min )
                            min = value;

                        if ( value > max )
                            max = value;
                    }
                    ptr += offset;
                }

                levelsLinear.InGray = new IntRange( min, max );
            }
            else
            {
                // allign pointer to the first pixel to process
                ptr += ( startY * stride + startX * pixelSize );

                byte minR = 255, minG = 255, minB = 255;
                byte maxR = 0,   maxG = 0,   maxB = 0;

                for ( int y = startY; y < stopY; y++ )
                {
                    for ( int x = startX; x < stopX; x++, ptr += pixelSize )
                    {
                        // red
                        byte value = ptr[RGB.R];

                        if ( value < minR )
                            minR = value;

                        if ( value > maxR )
                            maxR = value;

                        // green
                        value = ptr[RGB.G];

                        if ( value < minG )
                            minG = value;

                        if ( value > maxG )
                            maxG = value;

                        // blue
                        value = ptr[RGB.B];

                        if ( value < minB )
                            minB = value;

                        if ( value > maxB )
                            maxB = value;
                    }
                    ptr += offset;
                }

                levelsLinear.InRed   = new IntRange( minR, maxR );
                levelsLinear.InGreen = new IntRange( minG, maxG );
                levelsLinear.InBlue  = new IntRange( minB, maxB );
            }

            // STEP 2 - run levels linear correction
            levelsLinear.ApplyInPlace( image, rect );
        }
예제 #20
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Bitmap img = null;

            DA.GetData(0, ref img);
            Interval L = new Interval(0, 1);

            DA.GetData("Luminance", ref L);
            Interval S = new Interval(0, 1);

            DA.GetData("Saturation", ref S);
            Interval Y = new Interval(0, 255);

            DA.GetData("Luma", ref Y);
            Interval Cb = new Interval(-1, 1);

            DA.GetData("Chroma_Blue", ref Cb);
            Interval Cr = new Interval(-1, 1);

            DA.GetData("Chroma_Red", ref Cr);
            Interval R = new Interval(0, 255);

            DA.GetData("Red", ref R);
            Interval G = new Interval(0, 255);

            DA.GetData("Green", ref G);
            Interval B = new Interval(0, 255);

            DA.GetData("Blue", ref B);

            Bitmap filteredImage = img;

            Interval bInterval        = new Interval(0, 1);
            Interval Interval255      = new Interval(0, 255);
            Interval IntervalMinusOne = new Interval(-1, 1);

            //////////////////////////////////////////////////////////////////////////
            HSLLinear myHSLfilter = new HSLLinear();

            if (bInterval.IncludesInterval(L))
            {
                myHSLfilter.InLuminance = new AForge.Range(Convert.ToSingle(L.Min), Convert.ToSingle(L.Max));
            }
            if (bInterval.IncludesInterval(S))
            {
                myHSLfilter.InSaturation = new AForge.Range(Convert.ToSingle(S.Min), Convert.ToSingle(S.Max));
            }
            filteredImage = myHSLfilter.Apply(img);
            //////////////////////////////////////////////////////////////////////////
            YCbCrLinear myYCbCrfilter = new YCbCrLinear();

            if (Interval255.IncludesInterval(Y))
            {
                myYCbCrfilter.InCb = new AForge.Range(Convert.ToSingle(Y.Min), Convert.ToSingle(Y.Max));
            }
            if (IntervalMinusOne.IncludesInterval(Cb))
            {
                myYCbCrfilter.InCb = new AForge.Range(Convert.ToSingle(Cb.Min), Convert.ToSingle(Cb.Max));
            }
            if (IntervalMinusOne.IncludesInterval(Cr))
            {
                myYCbCrfilter.InCr = new AForge.Range(Convert.ToSingle(Cr.Min), Convert.ToSingle(Cr.Max));
            }
            filteredImage = myYCbCrfilter.Apply(filteredImage);
            //////////////////////////////////////////////////////////////////////////
            LevelsLinear myRGBfilter = new LevelsLinear();

            if (Interval255.IncludesInterval(R))
            {
                myRGBfilter.InRed = new AForge.IntRange((int)(R.Min), (int)(R.Max));
            }
            if (Interval255.IncludesInterval(G))
            {
                myRGBfilter.InGreen = new AForge.IntRange((int)(G.Min), (int)(G.Max));
            }
            if (Interval255.IncludesInterval(B))
            {
                myRGBfilter.InBlue = new AForge.IntRange((int)(B.Min), (int)(B.Max));
            }
            filteredImage = myRGBfilter.Apply(filteredImage);

            DA.SetData(0, filteredImage);
        }
예제 #21
0
        public IList <IFilter> GetFilterList(ImageProcessingSettings imageProcessingSettings)
        {
            var filterList = new List <IFilter>();

            // Brightness
            if (imageProcessingSettings.BrightnessAdjustment.Value != 0)
            {
                BrightnessCorrection filter = new BrightnessCorrection(imageProcessingSettings.BrightnessAdjustment.Value);
                filterList.Add(filter);
            }

            // Contrast
            if (imageProcessingSettings.ContrastAdjustment.Value != 0)
            {
                ContrastCorrection filter = new ContrastCorrection(imageProcessingSettings.ContrastAdjustment.Value);
                filterList.Add(filter);
            }

            // Saturation
            if (imageProcessingSettings.SaturationAdjustment.Value != 0)
            {
                // Only use 60% of the available correction range
                float adjustedValue = ((float)imageProcessingSettings.SaturationAdjustment.Value / 100) * 60;

                float value = (float)adjustedValue / 100;
                SaturationCorrection filter = new SaturationCorrection(value);
                filterList.Add(filter);
            }

            // Sharpness
            if (imageProcessingSettings.SharpnessAdjustment.Value != 0)
            {
                double          sigma  = 1.5;
                GaussianSharpen filter = new GaussianSharpen(sigma, imageProcessingSettings.SharpnessAdjustment.Value);
                filterList.Add(filter);
            }


            // Red, Green, Blue
            if (imageProcessingSettings.RedAdjustment.Value != 0 ||
                imageProcessingSettings.GreenAdjustment.Value != 0 ||
                imageProcessingSettings.BlueAdjustment.Value != 0)
            {
                LevelsLinear filter = new LevelsLinear();

                if (imageProcessingSettings.RedAdjustment.Value != 0)
                {
                    float val = ((float)imageProcessingSettings.RedAdjustment.Value / 100) * 255;

                    if (imageProcessingSettings.RedAdjustment.Value > 0)
                    {
                        var finalVal = 255 - (int)val;
                        filter.InRed = new IntRange(0, finalVal);
                    }
                    else
                    {
                        val          = val * -1;
                        filter.InRed = new IntRange((int)val, 255);
                    }
                }

                if (imageProcessingSettings.GreenAdjustment.Value != 0)
                {
                    float val = ((float)imageProcessingSettings.GreenAdjustment.Value / 100) * 255;

                    if (imageProcessingSettings.GreenAdjustment.Value > 0)
                    {
                        var finalVal = 255 - (int)val;
                        filter.InGreen = new IntRange(0, finalVal);
                    }
                    else
                    {
                        val            = val * -1;
                        filter.InGreen = new IntRange((int)val, 255);
                    }
                }

                if (imageProcessingSettings.BlueAdjustment.Value != 0)
                {
                    float val = ((float)imageProcessingSettings.BlueAdjustment.Value / 100) * 255;

                    if (imageProcessingSettings.BlueAdjustment.Value > 0)
                    {
                        var finalVal = 255 - (int)val;
                        filter.InBlue = new IntRange(0, finalVal);
                    }
                    else
                    {
                        val           = val * -1;
                        filter.InBlue = new IntRange((int)val, 255);
                    }
                }

                filterList.Add(filter);
            }


            return(filterList);
        }