private Bitmap processImage(Bitmap img) { //Generate closing structural element short[,] structEl = new short[13, 13]; for (int i = 0; i < 13; i++) for (int j = 0; j < 13; j++) if ((i - 6) * (i - 6) + (j - 6) * (j - 6) < 64) structEl[i, j] = 1; else structEl[i, j] = -1; //Initialize filters HSLFiltering borderFind = new HSLFiltering(); Closing borderClose = new Closing(structEl); Invert invert = new Invert(); Grayscale grayFilter = new Grayscale(0, 0, 1.0); Threshold bwFilter = new Threshold(1); PointedColorFloodFill blackout = new PointedColorFloodFill(); blackout.Tolerance = Color.FromArgb(0, 0, 0); blackout.FillColor = Color.FromArgb(0, 0, 0); ExtractBiggestBlob getgame = new ExtractBiggestBlob(); getgame.OriginalImage = new Bitmap(img); GrayscaleToRGB colorFilter = new GrayscaleToRGB(); //Color determined with ColorProbe. borderFind.Hue = new IntRange(190, 200); borderFind.Saturation = new Range(0.6f, 0.8f); borderFind.Luminance = new Range(0.6f, 1.0f); borderFind.ApplyInPlace(img); borderClose.ApplyInPlace(img); img = grayFilter.Apply(img); bwFilter.ApplyInPlace(img); invert.ApplyInPlace(img); img = colorFilter.Apply(img); blackout.StartingPoint = new AForge.IntPoint(0, 0); blackout.ApplyInPlace(img); img = getgame.Apply(img); int tilesx = img.Width / 56; int tilesy = img.Height / 56; int offsetx = 56 * (int)(tilesx - img.Width / 56.0); int offsety = 56 * (int)(tilesy - img.Height / 56.0); if ((Math.Abs(offsetx) > 11) || (Math.Abs(offsety) > 11)) throw new GameNotFoundException(); List<IntPoint> corners = new List<IntPoint>(); Dictionary<IntPoint, Bitmap> tiles = new Dictionary<IntPoint, Bitmap>(); SimpleQuadrilateralTransformation tileXtract = new SimpleQuadrilateralTransformation(); for (int j = 0; j < tilesy; j++) for (int i = 0; i < tilesx; i++) { corners.Add(new IntPoint(offsetx + i * 56, offsety + j * 56 )); corners.Add(new IntPoint(offsetx + i * 56, offsety + (j + 1) * 56 - 1)); corners.Add(new IntPoint(offsetx + (i + 1) * 56 - 1, offsety + (j + 1) * 56 - 1)); corners.Add(new IntPoint(offsetx + (i + 1) * 56 - 1, offsety + j * 56 )); tileXtract.SourceQuadrilateral = corners; tiles.Add(new IntPoint(i, j), tileXtract.Apply(img)); corners.Clear(); } img = (Bitmap)Properties.Resources.ResourceManager.GetObject("cb"); /*Graphics g = Graphics.FromImage(img); Pen bluePen = new Pen(Color.Blue, 2); for (int i = 0, n = blobs.Length; i < n; i++) { List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]); if (edgePoints.Count > 1) { List<IntPoint> corners = PointsCloud.FindQuadrilateralCorners(edgePoints); g.DrawPolygon(bluePen, ToPointsArray(corners)); } } bluePen.Dispose(); g.Dispose(); */ return img; }
/// <summary> /// Initializes a new instance of the <see cref="QuadrilateralTransformationNearestNeighbor"/> class. /// </summary> /// /// <param name="sourceCorners">Corners of the source quadrilateral area.</param> /// /// <remarks><para>This constructor sets <see cref="AutomaticSizeCalculaton"/> to /// <see langword="true"/>, which means that destination image will have width and /// height automatically calculated based on <see cref="SourceCorners"/> property.</para></remarks> /// public QuadrilateralTransformationNearestNeighbor(List <IntPoint> sourceCorners) { baseFilter = new SimpleQuadrilateralTransformation(sourceCorners) { UseInterpolation = false }; }
/// <summary> /// Initializes a new instance of the <see cref="QuadrilateralTransformationBilinear"/> class. /// </summary> /// /// <param name="sourceCorners">Corners of the source quadrilateral area.</param> /// /// <remarks><para>This constructor sets <see cref="AutomaticSizeCalculaton"/> to /// <see langword="true"/>, which means that destination image will have width and /// height automatically calculated based on <see cref="SourceCorners"/> property.</para></remarks> /// public QuadrilateralTransformationBilinear(List <IntPoint> sourceCorners) { baseFilter = new SimpleQuadrilateralTransformation(sourceCorners) { UseInterpolation = true }; }
/// <summary> /// Initializes a new instance of the <see cref="QuadrilateralTransformationBilinear"/> class. /// </summary> /// /// <param name="sourceCorners">Corners of the source quadrilateral area.</param> /// <param name="newWidth">Width of the new transformed image.</param> /// <param name="newHeight">Height of the new transformed image.</param> /// /// <remarks><para>This constructor sets <see cref="AutomaticSizeCalculaton"/> to /// <see langword="false"/>, which means that destination image will have width and /// height as specified by user.</para></remarks> /// public QuadrilateralTransformationBilinear(List <IntPoint> sourceCorners, int newWidth, int newHeight) { baseFilter = new SimpleQuadrilateralTransformation(sourceCorners, newWidth, newHeight); baseFilter.UseInterpolation = true; }
/// <summary> /// Initializes a new instance of the <see cref="QuadrilateralTransformationNearestNeighbor"/> class. /// </summary> /// /// <param name="sourceCorners">Corners of the source quadrilateral area.</param> /// <param name="newWidth">Width of the new transformed image.</param> /// <param name="newHeight">Height of the new transformed image.</param> /// /// <remarks><para>This constructor sets <see cref="AutomaticSizeCalculaton"/> to /// <see langword="false"/>, which means that destination image will have width and /// height as specified by user.</para></remarks> /// public QuadrilateralTransformationNearestNeighbor(List <IntPoint> sourceCorners, int newWidth, int newHeight) { this.baseFilter = new SimpleQuadrilateralTransformation(sourceCorners, newWidth, newHeight); this.baseFilter.UseInterpolation = false; }
/// <summary> /// Initializes a new instance of the <see cref="QuadrilateralTransformationNearestNeighbor"/> class. /// </summary> /// /// <param name="sourceCorners">Corners of the source quadrilateral area.</param> /// /// <remarks><para>This constructor sets <see cref="AutomaticSizeCalculaton"/> to /// <see langword="true"/>, which means that destination image will have width and /// height automatically calculated based on <see cref="SourceCorners"/> property.</para></remarks> /// public QuadrilateralTransformationNearestNeighbor( List<IntPoint> sourceCorners ) { baseFilter = new SimpleQuadrilateralTransformation( sourceCorners ); baseFilter.UseInterpolation = false; }
/// <summary> /// Initializes a new instance of the <see cref="QuadrilateralTransformationBilinear"/> class. /// </summary> /// /// <param name="sourceCorners">Corners of the source quadrilateral area.</param> /// /// <remarks><para>This constructor sets <see cref="AutomaticSizeCalculaton"/> to /// <see langword="true"/>, which means that destination image will have width and /// height automatically calculated based on <see cref="SourceCorners"/> property.</para></remarks> /// public QuadrilateralTransformationBilinear( List<IntPoint> sourceCorners ) { baseFilter = new SimpleQuadrilateralTransformation( sourceCorners ); baseFilter.UseInterpolation = true; }