/**
         * Apply the filter to a given BinaryImage.
         * All transformations will be done on a copy of the image and the original image will not be altered.
         **/
        public BinaryImage Apply(BinaryImage image)
        {
            BinaryImage newImage = new BinaryImage(new bool[image.Pixels.Length], image.Width, image.Height);

            for (int y = 0; y < image.Height; y++)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    bool pixel = image.getPixel(x, y);
                    newImage.setPixel(x, y, pixel);

                    if (!pixel)
                    {
                        continue;
                    }

                    for (int modX = halfStrokeWidth * (-1); modX < halfStrokeWidth; modX++)
                    {
                        int newX = x + modX;
                        if (newX > 0 && newX < image.Width)
                        {
                            newImage.setPixel(newX, y, pixel);
                        }
                    }

                    for (int modY = halfStrokeWidth * (-1); modY < halfStrokeWidth; modY++)
                    {
                        int newY = y + modY;
                        if (newY > 0 && newY < image.Height)
                        {
                            newImage.setPixel(x, newY, pixel);
                        }
                    }
                }
            }

            return(newImage);
        }
示例#2
0
        private List <Coordinate> getUnseenWhiteAdjacentPixels(Coordinate coordinate, Image image, BinaryImage seenMap)
        {
            int[][] modifiers =
            {
                new int[] {  0, -1 },            // up
                new int[] {  1, -1 },            // up-right
                new int[] {  1,  0 },            // right
                new int[] {  1,  1 },            // down-right
                new int[] {  0,  1 },            // down
                new int[] { -1,  1 },            // down-left
                new int[] { -1,  0 },            // left
                new int[] { -1, -1 }             // up-left
            };
            List <Coordinate> adjacentCoordinates = new List <Coordinate> ();

            foreach (int[] modifier in modifiers)
            {
                Coordinate modCoord = new Coordinate(coordinate.X + modifier[0], coordinate.Y + modifier[1]);
                if (modCoord.X < 0 || modCoord.X > image.Width - 1)
                {
                    continue;
                }

                if (modCoord.Y < 0 || modCoord.Y > image.Height - 1)
                {
                    continue;
                }

                if (!adjacentCoordinates.Contains(modCoord) && !seenMap.getPixel(modCoord.X, modCoord.Y) && !isBlackPixel(modCoord, image))
                {
                    adjacentCoordinates.Add(modCoord);
                    seenMap.setPixel(modCoord.X, modCoord.Y, true);
                }
            }

            return(adjacentCoordinates);
        }