Exemplo n.º 1
0
        private void FragmentContours()
        {
            var imageBitmap = new Bitmap(ImageFile.GetInstance().Image);

            if (!coordinatesAnalyze.IsEmpty)
            {
                var contoursBitmap = FragmentBitmap(imageBitmap);

                contoursBitmap = ImageFilter.PrewittFilter(contoursBitmap, false);
                FilteredImageForm filteredImageForm = new FilteredImageForm();
                filteredImageForm.Image = contoursBitmap;
                filteredImageForm.Show();
            }
            else
            {
                MessageBox.Show("Выберите участок карты!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        private void FragmentFindContours()
        {
            var imageFile   = ImageFile.GetInstance();
            var imageBitmap = new Bitmap(imageFile.Image);

            if (!coordinatesAnalyze.IsEmpty)
            {
                var fragmentBitmap = FragmentBitmap(imageBitmap);
                var contoursMat    = FindContoursAndDraw(fragmentBitmap, "Ponds");
                var contoursBitmap = BitmapConverter.ToBitmap(contoursMat);
                FilteredImageForm filteredImageForm = new FilteredImageForm();
                filteredImageForm.Image = contoursBitmap;
                filteredImageForm.Show();
            }
            else
            {
                MessageBox.Show("Выберите участок карты!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        private void DetectColors_Click(object sender, EventArgs e)
        {
            var imageFile      = ImageFile.GetInstance();
            var imageBitmap    = new Bitmap(imageFile.Image);
            var contoursBitmap = new Bitmap(imageBitmap);

            if (!coordinatesAnalyze.IsEmpty)
            {
                var xstart    = coordinatesAnalyze.X - RectSide / 2;
                var ystart    = coordinatesAnalyze.Y - RectSide / 2;
                var xend      = coordinatesAnalyze.X + RectSide / 2;
                var yend      = coordinatesAnalyze.Y + RectSide / 2;
                var xmin      = xstart > 0 ? xstart : 0;
                var ymin      = ystart > 0 ? ystart : 0;
                var xmax      = xend < Width ? xend : Width;
                var ymax      = yend < Height ? yend : Height;
                var newWidth  = xmax - xmin;
                var newHeight = ymax - ymin;
                for (int i = 0; i < newWidth; i++)
                {
                    for (int j = 0; j < newHeight; j++)
                    {
                        if (!(i == 0 || j == 0 || i == newWidth - 1 || j == newHeight - 1))
                        {
                            var medium = imageBitmap.GetPixel(i + xmin - 1, j + ymin - 1);
                            contoursBitmap.SetPixel(i, j, medium);
                        }
                    }
                }


                contoursBitmap = ImageFilter.PrewittFilter(contoursBitmap, false);
                var colorDictionary = new Dictionary <string, ColorInfo>();

                for (int i = 0; i < newWidth; i++)
                {
                    for (int j = 0; j < newHeight; j++)
                    {
                        if (!(i == 0 || j == 0 || i == newWidth - 1 || j == newHeight - 1))
                        {
                            var medium = contoursBitmap.GetPixel(i - 1, j - 1);
                            if (medium.ToArgb() != 0)
                            {
                                var colorValue = medium.ToArgb().ToString();

                                var near = ColorHelper.GetNearestColorName(ColorHelper.GetSystemDrawingColorFromHexString("#" + medium.Name.Substring(2)));
                                if (near != "Black")
                                {
                                    if (!colorDictionary.ContainsKey(colorValue))
                                    {
                                        colorDictionary.Add(colorValue, new ColorInfo {
                                            Color = medium, ColorCount = 1, NearColor = near
                                        });
                                    }
                                    else
                                    {
                                        colorDictionary[colorValue].ColorCount += 1;
                                    }
                                }
                            }
                        }
                    }
                }

                using (StreamWriter writer = new StreamWriter($@"{ProjectDir}\fragmentColors.txt"))
                {
                    foreach (KeyValuePair <string, ColorInfo> keyValue in colorDictionary.OrderByDescending(elem => elem.Value.ColorCount))
                    {
                        Color col  = Color.FromArgb(Convert.ToInt32(keyValue.Key));
                        var   near = ColorHelper.GetNearestColorName(ColorHelper.GetSystemDrawingColorFromHexString("#" + col.Name.Substring(2)));

                        writer.WriteLine($"{keyValue.Key} : {keyValue.Value.ColorCount} , near color = {keyValue.Value.NearColor}");
                        writer.WriteLine(near);
                    }
                }

                FilteredImageForm filteredImageForm = new FilteredImageForm();
                filteredImageForm.Image = contoursBitmap;
                filteredImageForm.Show();
            }
        }