public override TrainingData <Array3D, Array3D> GetNext(bool isTraining) { var imageFullPath = isTraining ? TrainPath : TestPath; var bitmap = new Bitmap(Image.FromFile(imageFullPath)); var column = rand.Next(_imageCount.Width); var row = rand.Next(_imageCount.Height); var origin = new Size { Width = _margin.Width + column * (_padding.Width + ImageSize.Width) + _padding.Width, Height = _margin.Height + row * (_padding.Height + ImageSize.Height) + _padding.Height }; var array = new Array3D(bitmap.Height, bitmap.Width, 3); for (var i = 0; i < bitmap.Height; i++) { for (var j = 0; j < bitmap.Width; j++) { var pixel = bitmap.GetPixel(j, i); array[origin.Height + i, origin.Width + j, 0] = pixel.R; array[origin.Height + i, origin.Width + j, 1] = pixel.G; array[origin.Height + i, origin.Width + j, 2] = pixel.B; } } //var pair = new TrainingData<Array3D, Array> { Expected = Classes[row], Input = array }; var pair = new TrainingData <Array3D, Array3D> { Expected = new Array3D(), Input = array }; return(pair); }
private void Initialize() { var image = Image.FromFile(TrainPath); Bitmap bitmap; if (ImageSize.Height == 0 || ImageSize.Width == 0) { bitmap = new Bitmap(image, image.Width, image.Height); } else { bitmap = new Bitmap(image, ImageSize.Width, ImageSize.Height); } var array = new Array3D(bitmap.Height, bitmap.Width, 3); for (var i = 0; i < bitmap.Height; i++) { for (var j = 0; j < bitmap.Width; j++) { var pixel = bitmap.GetPixel(j, i); array[i, j, 0] = pixel.R / 255.0; array[i, j, 1] = pixel.G / 255.0; array[i, j, 2] = pixel.B / 255.0; } } _pair = new TrainingData <Array3D, Array3D> { Expected = _expected, Input = array }; }