public static void GenerateImageNumSharp(int xwidth = 256, int yheight = 256) { var art = new ArtGenNumSharp(); 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\NumSharpTestImg.jpg"); }
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; npx.random.seed(KeyId.GetValueOrDefault()); } else { KeyId = Math.Abs(DateTime.Now.GetHashCode()); npx.random.seed(KeyId.GetValueOrDefault()); } var art = new ArtGenNumSharp(); 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(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>()); //var KeyId = 0; //if (seed != 0) //{ // KeyId = seed; // np.random.seed(seed); //} //else //{ // KeyId = Math.Abs(DateTime.Now.GetHashCode()); // np.random.seed(KeyId); //} //var z = np.random.uniform(-1.0, 1.0, new int[] { batchsize, hsize }).astype(np.float32); ////Generate Random Key to generate image //var data = CreateGrid(width, height, scaling); //X_Dat = data[0]; //Y_Dat = data[1]; //R_Dat = data[2]; //var art = BuildCPPN(width, height, X_Dat, Y_Dat, R_Dat, z); //var rgbData = np.multiply(art.flatten(), np.array(255)).ToArray<double>().ToList().ConvertAll(x => (byte)x); //return rgbData; }