Esempio n. 1
0
        static Bitmap modify(Bitmap im, ColorRange redRange, ColorRange greenRange, int[,] idMat, ref int currId)
        {
            Bitmap res = new Bitmap(im.Width, im.Height);

            for (int i = 1; i < im.Width-1; ++i)
            {
                for (int j = 1; j < im.Height-1; ++j)
                {
                    if (redRange.inRange(im.GetPixel(i, j)))
                    //if (im.GetPixel(i, j).isRed())
                    {
                        res.SetPixel(i, j, Color.red);
                        int idToUse = setId(im, idMat, ref currId, i, j);
                        dilate(im, ref res, Color.red, i, j, 10, idMat, idToUse);
                    }
                    else if (greenRange.inRange(im.GetPixel(i, j)))
                    //else if (im.GetPixel(i, j).isGreenLight())
                    {
                        res.SetPixel(i, j, Color.green);
                        int idToUse = setId(im, idMat, ref currId, i, j);
                        dilate(im, ref res, Color.green, i, j, 10, idMat, idToUse);
                    }
                }
            }

            return res;
        }
Esempio n. 2
0
        static void dilate(Bitmap orig, ref Bitmap res, Color paint, int x, int y, int w, int[,] idMat, int currId)
        {
            Color pixel = orig.GetPixel(x, y);
            ColorRange range = new ColorRange();
            int delta = 30;
            range.redMin = (int) (Math.Max(pixel.R - delta, 0));
            range.redMax = (int)(Math.Min(pixel.R + delta, 255));
            range.greenMin = (int)(Math.Max(pixel.G - delta, 0));
            range.greenMax = (int)(Math.Min(pixel.G + delta, 255));
            range.blueMin = (int)(Math.Max(pixel.B - delta, 0));
            range.blueMax = (int)(Math.Min(pixel.B + delta, 255));

            int startX = Math.Max(0, x - w);
            int endX = Math.Min(orig.Width, x + w);
            int startY = Math.Max(0, y - w);
            int endY = Math.Min(orig.Height, y + w);

            for (int i = startX; i < endX; ++i)
            {
                for (int j = startY; j < endY; ++j)
                {
                    if (idMat[i, j] != 0) continue;
                    if (range.inRange(orig.GetPixel(i, j)))
                    {
                        res.SetPixel(i, j, paint);
                        idMat[i, j] = currId;
                    }
                }
            }
        }