Esempio n. 1
0
        /// <summary>
        /// Получает контур замкнутой фигуры цвета <see cref="ContourColor"/>.
        /// </summary>
        /// <remarks>Поиск осуществляется алгоритмом левой руки.</remarks>
        /// <returns>Список точек контура по часовой стрелке.</returns>
        public static List <Point> FindContour(Bitmap bitmap)
        {
            var result = new List <Point>();

            var img = new ImageWrapper(bitmap, true);


            using (img)
            {
                var clockwiseOffsetPoints = new (int dx, int dy)[]
Esempio n. 2
0
        /// <summary>
        /// Ищет точку, которая однозначно входит в контур фигуры цветом <see cref="ContourColor"/>.
        /// Причём поиск осуществляется слева направо.
        /// </summary>
        private static Point?FindAnyContourPoint(ImageWrapper b)
        {
            var er = b.GetEnumerator();

            while (er.MoveNext())
            {
                Color cur = b[er.Current];
                if (cur.R == ContourColor.R && cur.G == ContourColor.G && cur.B == ContourColor.B)
                {
                    return(er.Current);
                }
            }

            return(null);
        }
Esempio n. 3
0
        public static Image <Gray, byte> DeleteTheBackground(Image <Gray, byte> img, Image <Gray, byte> bimg)
        {
            var source = new ImageWrapper(img.ToBitmap());

            var result = new System.Drawing.Bitmap(source.Width, source.Height);

            var mask = new ImageWrapper(bimg.ToBitmap());

            var en = source.GetEnumerator();


            while (en.MoveNext())
            {
                var point = en.Current;
                var color = mask[point].GetBrightness() == 1 ? System.Drawing.Color.White : source[point];
                result.SetPixel(point.X, point.Y, color);
            }
            Image <Gray, byte> image = new Image <Gray, byte>(result);

            return(image);
        }