public double[] GenerateArt(int batch_size = 1, int net_size = 16, int h_size = 8, int width = 512, int height = 512, float scaling = 10.0f, bool RGB = true, int?seed = null) { int?KeyId = null; if (seed != null) { KeyId = seed; random = new np.random(); random.seed(KeyId); } else { KeyId = Math.Abs(DateTime.Now.GetHashCode()); random = new np.random(); random.seed(KeyId); } var art = new ArtGenNumpyDotNet(); art.InitialiseCPPN(batch_size, net_size, RGB: RGB); if (RGB) { C_Dim = 3; } else { C_Dim = 1; } var imageData = art.Generate(width, height, scaling); var imgData = np.array(np.array(1) - imageData); if (C_Dim > 1) { imgData = np.array(imgData.reshape((height, width, C_Dim)) * 255.0); } else { imgData = np.array(imgData.reshape((height, width)) * 255.0); } return(imgData.ToArray <double>()); }
public static void GenerateImageNumpyDotNet(int xwidth = 256, int yheight = 256) { var art = new ArtGenNumpyDotNet(); var barray = art.GenerateArt(batch_size: 1, net_size: 8, h_size: 16, width: xwidth, height: yheight, scaling: 5.0f, RGB: false, seed: 040692); Image <Rgba32> image = new Image <Rgba32>(xwidth, yheight); var Count = 0; for (int y = 0; y < xwidth; y++) { for (int x = 0; x < yheight; x++) { Rgba32 pixel = image[x, y]; pixel.R = (byte)barray[Count]; pixel.G = (byte)barray[Count]; pixel.B = (byte)barray[Count]; pixel.A = 255; image[x, y] = pixel; Count++; } } image.Save(@"C:\temp\NumpyTestImg.jpg"); }