private static void GenerateGarbageData(EncogOCR_SketchData[] sketches, int outputSize, List<double[]> inputs, List<double[]> outputs) { #region validate #if DEBUG if (sketches.Select(o => o.BitmapColors.Width).Distinct().Count() != 1 || sketches.Select(o => o.BitmapColors.Height).Distinct().Count() != 1) { throw new ApplicationException("Stored images are different sizes"); } #endif #endregion double[] zeroOutput = Enumerable.Range(0, outputSize).Select(o => 0d).ToArray(); #region efficient if only a final is needed //Color[][] colors = sketches. // Select(o => o.BitmapColors.GetColors(0, 0, o.Bitmap.PixelWidth, o.Bitmap.PixelHeight)). // ToArray(); //bool[] isBlack = Enumerable.Range(0, colors[0].Length). // AsParallel(). // Select(o => new { Index = o, IsBlack = colors.Any(p => p[o].A > 200 && Math3D.Avg(p[o].R, p[o].G, p[o].B) < 20) }). // OrderBy(o => o.Index). // Select(o => o.IsBlack). // ToArray(); #endregion // Figure out which pixels of each sketch are black bool[][] isBlack = sketches. Select(o => o.BitmapColors.GetColors(0, 0, o.BitmapColors.Width, o.BitmapColors.Height)). Select(o => o.Select(p => p.A > 200 && Math1D.Avg(p.R, p.G, p.B) < 20).ToArray()). ToArray(); // Or the images together bool[] composite = Enumerable.Range(0, isBlack[0].Length). AsParallel(). Select(o => new { Index = o, IsBlack = isBlack.Any(p => p[o]) }). OrderBy(o => o.Index). Select(o => o.IsBlack). ToArray(); #region Blank sketch double[] percentBlack = isBlack. Select(o => o.Sum(p => p ? 1d : 0d) / o.Length). ToArray(); if (percentBlack.All(o => o > .01)) { // None of the inputs are blank, so make blank a garbage state inputs.Add(Enumerable.Range(0, composite.Length).Select(o => 0d).ToArray()); outputs.Add(zeroOutput); } #endregion #region Inverted sketch // Making this, because the assumption is that if they draw in a region outside any of the inputs, then it should be a zero output inputs.Add(composite.Select(o => o ? 0d : 1d).ToArray()); outputs.Add(zeroOutput); #endregion //TODO: Do a few subsets of inverted }