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; } }
private void CorrectLevel(int MinLevel, int MaxLevel) { LevelsLinear filter = new LevelsLinear(); filter.Input = new IntRange(MinLevel, MaxLevel); filter.ApplyInPlace(_recogimg); }
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); }
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; }
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); }
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"); } }
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); }
/// <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 ); }
protected override void ProcessFilter(BitmapData imageData) { levelsLinear.InGray = new IntRange(Min, Max); levelsLinear.ApplyInPlace(imageData); }