Example #1
0
        private static void TestDigitizerGetBackgroundColor()
        {
            Image           img        = Image.FromFile("samples\\gridlines.gif");
            NuGenDiscretize discretize = new NuGenDiscretize(img, new DiscretizeSettings());

            discretize.GetBackgroundColor();
        }
Example #2
0
        public void Discretize_Settings_Click(object sender, System.EventArgs args)
        {
            Cursor prev = activeView.Cursor;

            activeView.Cursor = Cursors.WaitCursor;

            form.Refresh();
            activeView.Refresh();

            DiscretizeSettingsDialog dlg = new DiscretizeSettingsDialog(ActiveDocument.DiscretizeSettings, ActiveDocument.OriginalImage);

            activeView.Cursor = prev;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                NuGenDiscretize discretize = new NuGenDiscretize(ActiveDocument.OriginalImage, dlg.DiscretizeSettings);

                discretize.Discretize();
                ActiveDocument.ProcessedImage = discretize.GetImage();

                ActiveDocument.DiscretizeSettings = dlg.DiscretizeSettings;

                ActiveDocument.Segments.MakeSegments(ActiveDocument.ProcessedImage, ActiveDocument.SegmentSettings);

                activeView.DrawAll();
                activeView.Refresh();
            }
        }
        public ImageHistogram(Image image, DiscretizeSettings settings)
        {
            this.image = new Bitmap(image.Clone() as Image);
            this.settings = settings;

            discretize = new NuGenDiscretize(new Bitmap(image), settings);

            switch (settings.discretizeMethod)
            {
                case DiscretizeMethod.DiscretizeForeground :
                    histogramData = new int[101]; displayData = new int[101]; break;
                case DiscretizeMethod.DiscretizeHue :
                    histogramData = new int[361]; displayData = new int[361]; break;
                case DiscretizeMethod.DiscretizeIntensity:
                    histogramData = new int[101]; displayData = new int[101]; break;
                case DiscretizeMethod.DiscretizeSaturation:
                    histogramData = new int[101]; displayData = new int[101]; break;
                case DiscretizeMethod.DiscretizeValue:
                    histogramData = new int[101]; displayData = new int[101]; break;
            }

            innerPanel = new Panel();
            innerPanel.Size = new Size(Width - pad, Height - pad - slidersSize);
            innerPanel.Location = new Point(pad / 2, pad / 2);
            innerPanel.Paint += new PaintEventHandler(innerPanel_Paint);

            lowBar = new TrackBar();
            lowBar.Location = new Point(0, innerPanel.Location.Y + innerPanel.Height + 5);
            lowBar.Size = new Size(Width, 25);
            lowBar.TickStyle = TickStyle.None;
            lowBar.Minimum = 0;
            lowBar.Maximum = 100;
            lowBar.AutoSize = false;
            lowBar.ValueChanged += new EventHandler(lowBar_ValueChanged);
            lowBar.MouseUp += new MouseEventHandler(lowBar_MouseUp);

            highBar = new TrackBar();
            highBar.Location = new Point(lowBar.Location.X, lowBar.Location.Y + lowBar.Height + 5);
            highBar.Size = new Size(Width, 25);
            highBar.TickStyle = TickStyle.None;
            highBar.AutoSize = false;
            highBar.Minimum = 0;
            highBar.Maximum = 100;
            highBar.ValueChanged += new EventHandler(highBar_ValueChanged);
            highBar.MouseUp += new MouseEventHandler(highBar_MouseUp);
            
            this.DoubleBuffered = true;            

            Controls.Add(innerPanel);
            Controls.Add(lowBar);
            Controls.Add(highBar);

            this.BorderStyle = BorderStyle.Fixed3D;

            lowBar.Value = GetLowThreshold();
            highBar.Value = GetHighThreshold();
        }
Example #4
0
        private void DiscretizeGo()
        {
            NuGenDiscretize discretize = new NuGenDiscretize(originalImage.Clone() as Image, settings);

            discretize.Discretize();
            Image img = discretize.GetImage();

            previewPanel.BackgroundImage = img;
            Refresh();

            discretizeThread = null;
        }
Example #5
0
 void LoadBool(bool[] columnBool,
               BitmapData bmData, int x)
 {
     for (int y = 0; y < bmData.Height; y++)
     {
         if (x < 0)
         {
             columnBool[y] = false;
         }
         else
         {
             columnBool[y] = NuGenDiscretize.ProcessedPixelIsOn(bmData, x, y);
         }
     }
 }
        //The main processing method, runs through all of the processing logic
        public void Process()
        {
            NuGenDiscretize discretize = new NuGenDiscretize(originalImage, doc.DiscretizeSettings);
            NuGenGridRemoval gridRemoval = new NuGenGridRemoval(originalImage, discretize);
            bgColor = discretize.GetBackgroundColor();
            gridRemoval.RemoveAndConnect(doc.Transform, doc.CoordSettings,
                                            doc.GridRemovalSettings, bgColor);

            discretize.Discretize();

            processedImage = discretize.GetImage();

            NuGenSegmentCollection segments = doc.Segments;
            segments.MakeSegments(processedImage, doc.SegmentSettings);
        }
Example #7
0
        private void DiscretizeGo()
        {
            NuGenDiscretize  discretize  = new NuGenDiscretize(originalImage.Clone() as Image, discretizeSettings);
            NuGenGridRemoval gridRemoval = new NuGenGridRemoval(originalImage, discretize);

            gridRemoval.RemoveAndConnect(transform, coordSettings, settings, bgColor);

            Image img = gridRemoval.GetImage();

            previewPanel.BackgroundImage       = img;
            previewPanel.BackgroundImageLayout = ImageLayout.Stretch;
            Refresh();

            discretizeThread = null;
        }
Example #8
0
        // initializes a new document by importing an image file
        public bool ImportFile(string filename)
        {
            originalImage = Image.FromFile(filename);

            ProcessOriginialImage();

            NuGenDiscretize discretize = new NuGenDiscretize(originalImage, discretizeSettings);

            gridRemovalSettings.color = discretize.GetBackgroundColor();

            saveFileExists = false;
            SavePath       = filename;

            UpdateListenersImage(originalImage);

            return(true);
        }
        //The main processing method, runs through all of the processing logic
        public void Process()
        {
            NuGenDiscretize  discretize  = new NuGenDiscretize(originalImage, doc.DiscretizeSettings);
            NuGenGridRemoval gridRemoval = new NuGenGridRemoval(originalImage, discretize);

            bgColor = discretize.GetBackgroundColor();
            gridRemoval.RemoveAndConnect(doc.Transform, doc.CoordSettings,
                                         doc.GridRemovalSettings, bgColor);

            discretize.Discretize();

            processedImage = discretize.GetImage();

            NuGenSegmentCollection segments = doc.Segments;

            segments.MakeSegments(processedImage, doc.SegmentSettings);
        }
Example #10
0
        private static void TestDiscretize()
        {
            Image           img        = Image.FromFile("samples\\gridlines.gif");
            NuGenDiscretize discretize = new NuGenDiscretize(img, NuGenDefaultSettings.GetInstance().DiscretizeSettings);

            discretize.Discretize();

            Form f = new Form();

            f.Size = new Size(img.Width, img.Height);

            f.BackgroundImage = discretize.GetImage();

            f.ShowDialog();

            System.Threading.Thread.Sleep(10000);
        }
Example #11
0
        private static void ConvertImageToArray(Image imageProcessed, out int[,] imageArray, out int imageWidth, out int imageHeight)
        {
            // compute bounds
            imageWidth  = imageProcessed.Width;
            imageHeight = imageProcessed.Height;

            // allocate memory
            imageArray = new int[imageWidth, imageHeight];

            // initialize memory
            Bitmap     b      = new Bitmap(imageProcessed);
            BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadOnly, b.PixelFormat);

            for (int x = 0; x < imageWidth; x++)
            {
                for (int y = 0; y < imageHeight; y++)
                {
                    imageArray[x, y] = NuGenDiscretize.ProcessedPixelIsOn(bmData, x, y) ? (int)PixelStates.PixelOnUnscanned : (int)PixelStates.PixelOff;
                }
            }

            b.UnlockBits(bmData);
        }
Example #12
0
        //Highlights a point in point match mode that is a candidate for the start of
        // a point match sequence
        public void HighlightCandidateMatchPoint(Point p)
        {
            Bitmap     b      = new Bitmap(processedImage);
            BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadOnly, b.PixelFormat);

            if (NuGenDiscretize.ProcessedPixelIsOn(bmData, p.X, p.Y))
            {
                // pixel is on
                bool found = (samplePointPixels.Count > 0);
                if (found)
                {
                    foreach (Point sample in samplePointPixels)
                    {
                        if (sample.X == p.X && sample.Y == p.Y)
                        {
                            found = true;
                            break;
                        }

                        found = false;
                    }
                }

                if (!found)
                {
                    NuGenPointMatch.IsolateSampleMatchPoint(samplePointPixels,
                                                            bmData, pointMatchSettings,
                                                            p.X, p.Y, p.X, p.Y);
                }
            }
            else
            {
                samplePointPixels.Clear();
            }

            b.UnlockBits(bmData);
        }
Example #13
0
        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);
        }
 //Creates this grid remover operating on the image, using the given discretize settings
 public NuGenGridRemoval(Image img, NuGenDiscretize discretize)
 {
     bmp = new Bitmap(img);
     this.discretize = discretize;
 }
Example #15
0
        private static void TestDiscretize()
        {
            Image img = Image.FromFile("samples\\gridlines.gif");
            NuGenDiscretize discretize = new NuGenDiscretize(img, NuGenDefaultSettings.GetInstance().DiscretizeSettings);

            discretize.Discretize();

            Form f = new Form();
            f.Size = new Size(img.Width, img.Height);

            f.BackgroundImage = discretize.GetImage();

            f.ShowDialog();

            System.Threading.Thread.Sleep(10000);
        }
Example #16
0
 //Creates this grid remover operating on the image, using the given discretize settings
 public NuGenGridRemoval(Image img, NuGenDiscretize discretize)
 {
     bmp             = new Bitmap(img);
     this.discretize = discretize;
 }
Example #17
0
        public void Discretize_Settings_Click(object sender, System.EventArgs args)
        {
            Cursor prev = activeView.Cursor;
            activeView.Cursor = Cursors.WaitCursor;

            form.Refresh();
            activeView.Refresh();

            DiscretizeSettingsDialog dlg = new DiscretizeSettingsDialog(ActiveDocument.DiscretizeSettings, ActiveDocument.OriginalImage);

            activeView.Cursor = prev;            

            if(dlg.ShowDialog() == DialogResult.OK)
            {
                NuGenDiscretize discretize = new NuGenDiscretize(ActiveDocument.OriginalImage, dlg.DiscretizeSettings);

                discretize.Discretize();
                ActiveDocument.ProcessedImage = discretize.GetImage();

                ActiveDocument.DiscretizeSettings = dlg.DiscretizeSettings;

                ActiveDocument.Segments.MakeSegments(ActiveDocument.ProcessedImage, ActiveDocument.SegmentSettings);

                activeView.DrawAll();
                activeView.Refresh();
            }
        }
Example #18
0
 private static void TestDigitizerGetBackgroundColor()
 {
     Image img = Image.FromFile("samples\\gridlines.gif");
     NuGenDiscretize discretize = new NuGenDiscretize(img, new DiscretizeSettings());
     discretize.GetBackgroundColor();
 }
Example #19
0
        public ImageHistogram(Image image, DiscretizeSettings settings)
        {
            this.image    = new Bitmap(image.Clone() as Image);
            this.settings = settings;

            discretize = new NuGenDiscretize(new Bitmap(image), settings);

            switch (settings.discretizeMethod)
            {
            case DiscretizeMethod.DiscretizeForeground:
                histogramData = new int[101]; displayData = new int[101]; break;

            case DiscretizeMethod.DiscretizeHue:
                histogramData = new int[361]; displayData = new int[361]; break;

            case DiscretizeMethod.DiscretizeIntensity:
                histogramData = new int[101]; displayData = new int[101]; break;

            case DiscretizeMethod.DiscretizeSaturation:
                histogramData = new int[101]; displayData = new int[101]; break;

            case DiscretizeMethod.DiscretizeValue:
                histogramData = new int[101]; displayData = new int[101]; break;
            }

            innerPanel          = new Panel();
            innerPanel.Size     = new Size(Width - pad, Height - pad - slidersSize);
            innerPanel.Location = new Point(pad / 2, pad / 2);
            innerPanel.Paint   += new PaintEventHandler(innerPanel_Paint);

            lowBar               = new TrackBar();
            lowBar.Location      = new Point(0, innerPanel.Location.Y + innerPanel.Height + 5);
            lowBar.Size          = new Size(Width, 25);
            lowBar.TickStyle     = TickStyle.None;
            lowBar.Minimum       = 0;
            lowBar.Maximum       = 100;
            lowBar.AutoSize      = false;
            lowBar.ValueChanged += new EventHandler(lowBar_ValueChanged);
            lowBar.MouseUp      += new MouseEventHandler(lowBar_MouseUp);

            highBar               = new TrackBar();
            highBar.Location      = new Point(lowBar.Location.X, lowBar.Location.Y + lowBar.Height + 5);
            highBar.Size          = new Size(Width, 25);
            highBar.TickStyle     = TickStyle.None;
            highBar.AutoSize      = false;
            highBar.Minimum       = 0;
            highBar.Maximum       = 100;
            highBar.ValueChanged += new EventHandler(highBar_ValueChanged);
            highBar.MouseUp      += new MouseEventHandler(highBar_MouseUp);

            this.DoubleBuffered = true;

            Controls.Add(innerPanel);
            Controls.Add(lowBar);
            Controls.Add(highBar);

            this.BorderStyle = BorderStyle.Fixed3D;

            lowBar.Value  = GetLowThreshold();
            highBar.Value = GetHighThreshold();
        }
        private void DiscretizeGo()
        {
            NuGenDiscretize discretize = new NuGenDiscretize(originalImage.Clone() as Image, settings);
            discretize.Discretize();
            Image img = discretize.GetImage();

            previewPanel.BackgroundImage = img;
            Refresh();

            discretizeThread = null;
        }
        private void DiscretizeGo()
        {            
            NuGenDiscretize discretize = new NuGenDiscretize(originalImage.Clone() as Image, discretizeSettings);
            NuGenGridRemoval gridRemoval = new NuGenGridRemoval(originalImage, discretize);

            gridRemoval.RemoveAndConnect(transform, coordSettings, settings, bgColor);

            Image img = gridRemoval.GetImage();

            previewPanel.BackgroundImage = img;
            previewPanel.BackgroundImageLayout = ImageLayout.Stretch;
            Refresh();

            discretizeThread = null;
        }