private FillSource _GetCurrentFillSource()
        {
            AnalyzeArea analyzeArea      = this._GetCurrentAnalyzeArea();
            Bitmap      analyzeAreaImage = analyzeArea.GetImage(this._Project.X, this._Project.Y);

            int[,] labels = new int[analyzeAreaImage.Width, analyzeAreaImage.Height];

            for (int x = 0; x < analyzeAreaImage.Width; x++)
            {
                for (int y = 0; y < analyzeAreaImage.Height; y++)
                {
                    Color color = analyzeAreaImage.GetPixel(x, y);
                    if (color.R == 255 && color.G == 255 && color.B == 255)
                    {
                        labels[x, y] = 1;
                    }
                    else
                    {
                        labels[x, y] = 0;
                    }
                }
            }

            ConnectedComponents components = new ConnectedComponents(labels, 1);

            return(new FillSource(components, 1));
        }
Пример #2
0
        public int AnalyzeArea(AnalyzeArea analyzeArea)
        {
            if (analyzeArea.Enabled == false)
            {
                return(0);
            }

            Bitmap image            = new Bitmap(this.GetImage());
            Bitmap analyzeAreaImage = analyzeArea.GetImage(image.Width, image.Height);

            int pixels = 0;

            int startX = analyzeArea.X - analyzeArea.R - 1;

            startX = startX < 0 ? 0 : startX;

            int endX = analyzeArea.X + analyzeArea.R + 1;

            endX = endX > image.Width ? image.Width : endX;

            int startY = analyzeArea.Y - analyzeArea.R - 1;

            startY = startY < 0 ? 0 : startY;

            int endY = analyzeArea.Y + analyzeArea.R + 1;

            endY = endY > image.Height ? image.Height : endY;

            for (int x = startX; x < endX; x++)
            {
                for (int y = startY; y < endY; y++)
                {
                    Color analyzeAreaColor = analyzeAreaImage.GetPixel(x, y);

                    if (analyzeAreaColor.R == 255 && analyzeAreaColor.G == 255 && analyzeAreaColor.B == 255)
                    {
                        Color color   = image.GetPixel(x, y);
                        int   average = (int)((color.R + color.G + color.B) / 3);

                        if (average > analyzeArea.Threshold)
                        {
                            pixels++;
                        }
                    }
                }
            }

            return(pixels);
        }
Пример #3
0
        public double AnalyzeSpot(AnalyzeArea analyzeArea, int threshold)
        {
            double return_data = 0;

            if (analyzeArea.Enabled == false)
            {
                return(return_data);
            }

            Bitmap image            = this.GetBinarizedImage(threshold);
            Bitmap analyzeAreaImage = analyzeArea.GetImage(image.Width, image.Height);

            int startX = analyzeArea.X - analyzeArea.R - 1;

            startX = startX < 0 ? 0 : startX;

            int endX = analyzeArea.X + analyzeArea.R + 1;

            endX = endX > image.Width ? image.Width : endX;

            int startY = analyzeArea.Y - analyzeArea.R - 1;

            startY = startY < 0 ? 0 : startY;

            int endY = analyzeArea.Y + analyzeArea.R + 1;

            endY = endY > image.Height ? image.Height : endY;

            ConnectedComponents   components = ConnectedComponents.Analyze(image);
            Dictionary <int, int> labels     = new Dictionary <int, int>();

            //選択部分の取得
            Bitmap   imageEllipse = new Bitmap(image.Width, image.Height);
            Graphics g            = Graphics.FromImage(imageEllipse);

            g.Clear(Color.Black);
            g.FillEllipse(Brushes.White, analyzeArea.X - analyzeArea.R, analyzeArea.Y - analyzeArea.R, analyzeArea.R * 2, analyzeArea.R * 2);
            g.Dispose();

            for (int x = startX; x < endX; x++)
            {
                for (int y = startY; y < endY; y++)
                {
                    int   label = components.Labels[x, y];
                    Color color = imageEllipse.GetPixel(x, y);

                    if (label <= 0 || (color.R == 0 && color.G == 0 && color.B == 0))
                    {
                        continue;
                    }

                    if (labels.ContainsKey(label))
                    {
                        labels[label]++;
                    }
                    else
                    {
                        labels[label] = 1;
                    }
                }
            }

            return(labels.Count);
        }