void Start() { binaryThreshold = new BinaryThreshold(inputThresholds, false); parabolicArc = new CalculateParabolicArc(range, gravity, resolution, maxDrop); findHitsInPath = new FindHitsInPath(transform); calculateCutoff = new TeleportCutoffPath(transform, maxSlope, teleportTag); line = new LineRendererInterface(lineRenderer, shaderColorId); }
/// <summary> /// Processes the image. /// </summary> /// <param name="factory"> /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing /// the image to process. /// </param> /// <returns> /// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public Image ProcessImage(ImageFactory factory) { Bitmap newImage = null; Bitmap grey = null; var image = factory.Image; byte threshold = DynamicParameter; try { // Detect the edges then strip out middle shades. grey = new ConvolutionFilter(new SobelEdgeFilter(), true).Process2DFilter(image); grey = new BinaryThreshold(threshold).ProcessFilter(grey); // Search for the first white pixels var rectangle = ImageMaths.GetFilteredBoundingRectangle(grey, 0); grey.Dispose(); newImage = new Bitmap(rectangle.Width, rectangle.Height, PixelFormat.Format32bppPArgb); newImage.SetResolution(image.HorizontalResolution, image.VerticalResolution); using (var graphics = Graphics.FromImage(newImage)) { graphics.DrawImage( image, new Rectangle(0, 0, rectangle.Width, rectangle.Height), rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, GraphicsUnit.Pixel); } // Reassign the image. image.Dispose(); image = newImage; if (factory.PreserveExifData && factory.ExifPropertyItems.Any()) { // Set the width EXIF data. factory.SetPropertyItem(ExifPropertyTag.ImageWidth, (ushort)image.Width); // Set the height EXIF data. factory.SetPropertyItem(ExifPropertyTag.ImageHeight, (ushort)image.Height); } } catch (Exception ex) { grey?.Dispose(); newImage?.Dispose(); throw new ImageProcessingException("Error processing image with " + GetType().Name, ex); } return(image); }
/// <summary> /// Processes the image. /// </summary> /// <param name="factory"> /// The current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class containing /// the image to process. /// </param> /// <returns> /// The processed image from the current instance of the <see cref="T:ImageProcessor.ImageFactory"/> class. /// </returns> public Image ProcessImage(ImageFactory factory) { Bitmap newImage = null; Bitmap grey = null; Image image = factory.Image; byte threshold = this.DynamicParameter; try { // Detect the edges then strip out middle shades. grey = new ConvolutionFilter(new SobelEdgeFilter(), true).Process2DFilter(image); grey = new BinaryThreshold(threshold).ProcessFilter(grey); // Search for the first white pixels Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(grey, 0); grey.Dispose(); newImage = new Bitmap(rectangle.Width, rectangle.Height); newImage.SetResolution(image.HorizontalResolution, image.VerticalResolution); using (Graphics graphics = Graphics.FromImage(newImage)) { graphics.DrawImage( image, new Rectangle(0, 0, rectangle.Width, rectangle.Height), rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, GraphicsUnit.Pixel); } // Reassign the image. image.Dispose(); image = newImage; } catch (Exception ex) { if (grey != null) { grey.Dispose(); } if (newImage != null) { newImage.Dispose(); } throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex); } return(image); }
private static Image EntropyCropFull(Image image, byte treshold) { Bitmap newImage = null; Bitmap grey = null; try { // Detect the edges then strip out middle shades. grey = new ConvolutionFilter(new SobelEdgeFilter(), true).Process2DFilter(image); grey = new BinaryThreshold(treshold).ProcessFilter(grey); // Search for the first white pixels Rectangle rectangle = GetFilteredBoundingRectangle(grey, 0, RgbaComponent.R); grey.Dispose(); newImage = new Bitmap(rectangle.Width, rectangle.Height, PixelFormat.Format32bppPArgb); newImage.SetResolution(image.HorizontalResolution, image.VerticalResolution); using (Graphics graphics = Graphics.FromImage(newImage)) { graphics.DrawImage( image, new Rectangle(0, 0, rectangle.Width, rectangle.Height), rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, GraphicsUnit.Pixel); } // Reassign the image. image.Dispose(); image = newImage; return(image); //if (factory.PreserveExifData && factory.ExifPropertyItems.Any()) //{ // // Set the width EXIF data. // factory.SetPropertyItem(ExifPropertyTag.ImageWidth, (ushort)image.Width); // // Set the height EXIF data. // factory.SetPropertyItem(ExifPropertyTag.ImageHeight, (ushort)image.Height); //} } catch (Exception ex) { if (grey != null) { grey.Dispose(); } if (newImage != null) { newImage.Dispose(); } throw new Exception("Error processing image", ex); } return(image); }