예제 #1
0
        //Removes pixels around user defined gridlines
        private void RemoveGridlines(PixelState[,] pixels, NuGenScreenTranslate transform,
                                     CoordSettings coordSettings, GridRemovalSettings gridRemovalSettings, PixelState pxState)
        {
            if (transform.ValidAxes)
            {
                List <GridlineScreen> gridlines;
                gridlines = NuGenGridMesh.MakeGridLines(transform, coordSettings, gridRemovalSettings.gridMesh);

                foreach (GridlineScreen gridline in gridlines)
                {
                    int xStart = gridline.Start.X;
                    int yStart = gridline.Start.Y;
                    int xStop  = gridline.Stop.X;
                    int yStop  = gridline.Stop.Y;

                    if (Math.Abs(xStop - xStart) < Math.Abs(yStop - yStart))
                    {
                        //Vertical lines
                        RemoveGridlineVertical(pixels, xStart, yStart, xStop, yStop, gridRemovalSettings, pxState);
                    }
                    else
                    {
                        //Horizontal lines
                        RemoveGridlineHorizontal(pixels, xStart, yStart, xStop, yStop, gridRemovalSettings, pxState);
                    }
                }
            }
        }
예제 #2
0
        //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;
        }
예제 #3
0
        //Removes pixels of a certain color
        private void RemoveColor(PixelState[,] pixels, GridRemovalSettings gridSettings, PixelState pxState)
        {
            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    int value = discretize.DiscretizeValueForeground(x, y, gridSettings.color);

                    if (!discretize.PixelIsOn(value, gridSettings))
                    {
                        pixels[x, y] = pxState;
                    }
                }
            }
        }
예제 #4
0
        public GridRemovalSettingsDialog(NuGenDocument doc)
        {
            this.settings           = doc.GridRemovalSettings;
            this.originalImage      = doc.OriginalImage;
            this.discretizeSettings = doc.DiscretizeSettings;
            this.transform          = doc.Transform;
            this.bgColor            = doc.BackgroundColor;
            this.coordSettings      = doc.CoordSettings;

            if (doc.ValidAxes)
            {
                this.gridRemovalMesh = doc.GridDisplaySettings;
            }
            else
            {
                this.gridRemovalMesh.initialized = false;
            }

            discretizeSettings.discretizeMethod = DiscretizeMethod.DiscretizeForeground;

            InitializeComponent();
            InitializeDefaults();

            if (!(doc.ValidAxes || doc.ValidScale))
            {
                textBox1.Enabled  = false;
                textBox2.Enabled  = false;
                checkBox2.Enabled = false;
                checkBox2.Checked = false;
                checkBox3.Enabled = false;
                checkBox3.Checked = false;
            }

            histogram.ValueChanged = this.ValueChanged;

            ValueChanged(true);

            this.MaximumSize = Size;
        }
예제 #5
0
 //Tells if a pixel is on based on its color
 public bool PixelIsOn(int value, GridRemovalSettings settings)
 {
     return(PixelIsOn(value, settings.foregroundThresholdLow, settings.foregroundThresholdHigh));
 }
예제 #6
0
        //Remove gridlines and reconnect gaps
        public void RemoveAndConnect(NuGenScreenTranslate transform, CoordSettings coordSettings, GridRemovalSettings gridRemovalSettings, Color bgColor)
        {
            int width  = bmp.Width;
            int height = bmp.Height;

            PixelState[,] pixels = InitializePixels();

            // 1) Color removal
            if (gridRemovalSettings.removeColor)
            {
                RemoveColor(pixels, gridRemovalSettings, PixelState.PixelOnRemovedStage1);
            }


            // 2) Remove pixels around gridlines
            if (gridRemovalSettings.removeGridlines && gridRemovalSettings.gridDistance > 0.0)
            {
                RemoveGridlines(pixels, transform, coordSettings, gridRemovalSettings, PixelState.PixelOnRemovedStage2);
            }

            // 3) Remove thin lines parallel to the axes
            if (gridRemovalSettings.removeThinLines && gridRemovalSettings.thinThickness > 0.0)
            {
                RemoveThinLines(pixels, coordSettings, transform, gridRemovalSettings.thinThickness,
                                PixelState.PixelOnRemovedStage3, PixelState.PixelOnRemovedStage4);
            }

            // Reconnect the gaps created from the prior steps
            if (gridRemovalSettings.gapSeparation > 0.0)
            {
                ConnectNeuronsAcrossGaps(pixels, gridRemovalSettings.gapSeparation);
            }

            //Write the image
            SavePixels(pixels, bgColor);

            //Save the image
            discretize.SetImage(bmp);
        }
예제 #7
0
        private void RemoveGridlineVertical(PixelState[,] pixels, int xStart, int yStart, int xStop, int yStop, GridRemovalSettings gridSettings, PixelState pixelStateRemove)
        {
            // theta is the angle between the horizontal row and the gridline. since we
            // divide by sinTheta, this function should NOT be used for horizontal gridlines
            // since divide-by-zero error would occur
            if (yStart > yStop)
            {
                int temp = yStart;
                yStart = yStop;
                yStop  = temp;
                temp   = xStart;
                xStart = xStop;
                xStop  = temp;
            }

            double sinTheta;
            double atan;

            try
            {
                atan = Math.Atan2(yStop - yStart, xStop - xStart);
            }
            catch (Exception e)
            {
                atan = 0;
            }

            sinTheta = Math.Sin(atan);

            for (int y = (int)(yStart - gridSettings.gridDistance + 0.5);
                 y < (int)(yStop + gridSettings.gridDistance + 0.5); y++)
            {
                // interest this pixel row (y=yc) with the gridline (x-x0)/(x1-x0)=(y-y0)/(y1-y0)
                // to get (xp,yp)
                double sLine1, sLine2;
                try
                {
                    double[] results = IntersectTwoLines(0.0, y, this.bmp.Width, y, xStart, yStart, xStop, yStop);
                    sLine1 = results[0];
                    sLine2 = results[1];
                }
                catch (Exception e)
                {
                    //The lines did not intersect, so continue
                    continue;
                }
                double xp    = (1.0 - sLine2) * xStart + sLine2 * xStop;
                int    xLow  = (int)(-gridSettings.gridDistance / sinTheta + xp + 0.5);
                int    xHigh = (int)(gridSettings.gridDistance / sinTheta + xp + 0.5);
                for (int x = xLow; x <= xHigh; x++)
                {
                    bool include = true;
                    if (sLine2 < 0.0)
                    {
                        // at start end, the pixels have to be on the same side of (xStart,yStart) as
                        // (xStop,yStop), so use dot product to see if this pixel is on the same side
                        double dotProduct = (x - xStart) * (xStop - xStart) + (y - yStart) * (yStop - yStart);
                        include = (dotProduct >= 0.0);
                    }
                    else if (sLine2 > 1.0)
                    {
                        // at stop end, the pixels have to be on the same side of (xStop,yStop) as
                        // (xStart,yStart), so use dot product to see if this pixel is on the same side
                        double dotProduct = (x - xStop) * (xStart - xStop) + (y - yStop) * (yStart - yStop);
                        include = (dotProduct >= 0.0);
                    }

                    if (include && (0 <= x) && (x < this.bmp.Width) && (0 <= y) && (y < this.bmp.Height))
                    {
                        // overwrite this pixel with background color
                        pixels[x, y] = pixelStateRemove;
                    }
                }
            }
        }
예제 #8
0
 private static void TestDefaultSettings()
 {
     NuGenDefaultSettings s        = NuGenDefaultSettings.GetInstance();
     GridRemovalSettings  settings = s.GridRemovalSettings;
 }