//Constructs the document and places it in the provided state public NuGenDocument(DigitizeState state) { listeners = new List <NuGenImageListener>(); pointSets = new NuGenPointSetCollection(); segments = new NuGenSegmentCollection(); transform = new NuGenScreenTranslate(this); gridDisplay = new List <GridlineScreen>(); digitizeState = state; matchSet = new NuGenMatchSet(pointMatchSettings); //load all of the settings NuGenDefaultSettings rSettings = NuGenDefaultSettings.GetInstance(); coordSettings = rSettings.CoordSettings; exportSettings = rSettings.ExportSettings; segmentSettings = rSettings.SegmentSettings; pointMatchSettings = rSettings.PointMatchSettings; gridRemovalSettings = rSettings.GridRemovalSettings; gridDisplaySettings.initialized = false; gridDisplaySettings.gridSetX = rSettings.GridDisplayGridSetX; gridDisplaySettings.gridSetY = rSettings.GridDisplayGridSetY; discretizeSettings = rSettings.DiscretizeSettings; backgroundSelection = rSettings.BackgroundSelection; }
//Matches a point to the sample matched point public static void MatchSamplePoint(Image imageProcessed, PointMatchSettings settings, List <Point> samplePointPixels, List <Point> pointsExisting, List <PointMatchTriplet> pointsCreated) { // create sample point array bool[,] sampleMaskArray; int sampleMaskWidth = 0, sampleMaskHeight = 0; int sampleXCenter, sampleYCenter; ConvertSampleToArray(samplePointPixels, out sampleMaskArray, ref sampleMaskWidth, ref sampleMaskHeight, out sampleXCenter, out sampleYCenter); // create image array int[,] imageArray; int imageWidth, imageHeight; ConvertImageToArray(imageProcessed, out imageArray, out imageWidth, out imageHeight); RemovePixelsNearCurrentPoints(imageArray, imageWidth, imageHeight, pointsExisting, settings.pointSeparation); List <PointMatchTriplet> listCreated = new List <PointMatchTriplet>(); ScanImage(sampleMaskArray, sampleMaskWidth, sampleMaskHeight, sampleXCenter, sampleYCenter, settings, imageArray, imageWidth, imageHeight, listCreated); Comparison <PointMatchTriplet> comparison = new Comparison <PointMatchTriplet>(CompareTriplet); listCreated.Sort(comparison); foreach (PointMatchTriplet t in listCreated) { pointsCreated.Add(t); } }
public PointMatchDialog(PointMatchSettings settings) { this.settings = settings; InitializeComponent(); InitializeDefaults(); this.MaximumSize = Size; }
public static void ScanImage(bool[,] sampleMaskArray, int sampleMaskWidth, int sampleMaskHeight, int sampleXCenter, int sampleYCenter, PointMatchSettings settings, int[,] imageArray, int imageWidth, int imageHeight, List <PointMatchTriplet> pointsCreated) { // loop through image to first on-pixel for (int x = 0; x < imageWidth; x++) { for (int y = 0; y < imageHeight; y++) { bool firstMax = true; int onCount = 0, xSum = 0, ySum = 0; int xMin = imageWidth, xMax = 0; int yMin = imageHeight, yMax = 0; double correlationMax = 0.0; RecurseThroughOnRegion(sampleMaskArray, sampleMaskWidth, sampleMaskHeight, sampleXCenter, sampleYCenter, imageArray, imageWidth, imageHeight, x, y, ref firstMax, ref onCount, ref xSum, ref ySum, ref xMin, ref xMax, ref yMin, ref yMax, ref correlationMax); // save max if its correlation is positive and the point is not too big. a zero // correlation is would be expected from two uncorrelated sets of pixels, and // a negative correlation means the sets of pixels are inverses if (!firstMax && (correlationMax > 0) && (xMax - xMin < settings.pointSize) && (yMax - yMin < settings.pointSize)) { PointMatchTriplet p = new PointMatchTriplet(); if (onCount < 0) { onCount = 1; } p.x = (int)((double)xSum / (double)onCount + 0.5); p.y = (int)((double)ySum / (double)onCount + 0.5); p.correlation = correlationMax; pointsCreated.Add(p); } } } }
public NuGenMatchSet(PointMatchSettings settings) { this.settings = settings; }
public static bool IsolateSampleMatchPoint(List <Point> samplePointPixels, BitmapData bmData, PointMatchSettings settings, int xStart, int yStart, int x, int y) { if ((x < 0) || (y < 0) || (bmData.Width <= x) || (bmData.Height <= y)) { return(false); // out of bounds } if (!NuGenDiscretize.ProcessedPixelIsOn(bmData, x, y)) { return(false); // pixel is off } if (Math.Abs(x - xStart) > settings.pointSize / 2) { return(false); // point is too far from start } if (Math.Abs(y - yStart) > settings.pointSize / 2) { return(false); // point is too far from start } bool found = (samplePointPixels.Count > 0); if (found) { foreach (Point p in samplePointPixels) { if (p.X == x && p.Y == y) { found = true; break; } found = false; } } if (found) { return(true); // already in list } // add this point samplePointPixels.Add(new Point(x, y)); // recurse. diagonal points are included so single-pixel wide polygonal outlines will be traversed, // but for a 2x speed increase we only go diagonal if the adjacent nondiagonal pixels are off bool right = IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x + 1, y); bool up = IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x, y + 1); bool left = IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x - 1, y); bool down = IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x, y - 1); if (!right && !up) { IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x + 1, y + 1); } if (!up && !left) { IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x - 1, y + 1); } if (!left && !down) { IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x - 1, y - 1); } if (!down && !right) { IsolateSampleMatchPoint(samplePointPixels, bmData, settings, xStart, yStart, x + 1, y - 1); } return(true); }