Пример #1
0
    private EnhancedImage ParseGrid(IEnumerable <string> grid)
    {
        var image = new EnhancedImage();
        int y     = 0;

        foreach (var line in grid)
        {
            for (int x = 0; x < line.Length; x++)
            {
                image.SetPixel(new Point(x, y), line[x]);
            }
            y++;
        }
        return(image);
    }
Пример #2
0
    private EnhancedImage Enhance(EnhancedImage image, string algorithm)
    {
        var newImage = new EnhancedImage();

        foreach (var p in Point.EnumeratePoints(image.Xmin - 1, image.Ymin - 1, image.Xmax + 1, image.Ymax + 1))
        {
            string binary = String.Join("", p.SelectAdjacents(Grid2D.allNeighbours).Append(p)
                                        .OrderBy(adj => adj.Y).ThenBy(adj => adj.X).Select(image.ExtendedValueAt));
            var newPixel = algorithm[(int)Helpers.ParseBinary(
                                         binary)];
            newImage.SetPixel(p, newPixel);
        }
        newImage.OutOfBoundsValue = algorithm[(int)Helpers.ParseBinary(
                                                  Enumerable.Repeat(image.OutOfBoundsValue, 9).AsString())];
        return(newImage);
    }