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; }
protected override void ProcessFilter(UnmanagedImage image) { UnmanagedImage unmanagedImage = image.Clone(); closing.ApplyInPlace(image); subtract.UnmanagedOverlayImage = unmanagedImage; subtract.ApplyInPlace(image); unmanagedImage.Dispose(); }
/// <summary> /// Process the filter on the specified image. /// </summary> /// /// <param name="image">Source image data.</param> /// protected override unsafe void ProcessFilter(UnmanagedImage image) { // copy source image UnmanagedImage sourceImage = image.Clone( ); // perform closing on the source image closing.ApplyInPlace(image); // subtract source image from the closed image subtract.UnmanagedOverlayImage = sourceImage; subtract.ApplyInPlace(image); sourceImage.Dispose( ); }