/// <summary> /// get score. score of 0 is perfect /// </summary> /// <param name="b">The b.</param> /// <param name="l">The l.</param> /// <returns></returns> private int GetOffScore(Bitmap b, HistogramLetter l) { var bba = BitmapBoolArray.GetBitmapBoolArray(b); var h = HistogramLetter.GetHistogram(bba, b); var score = l.GetHistogramOffsetScore(h.Item1, h.Item2); return(score); }
/// <summary> /// Initializes a new instance of the <see cref="HistogramLetter"/> class. /// </summary> /// <param name="b">The b.</param> /// <param name="letter">The letter.</param> public HistogramLetter(Bitmap b, char letter) { var bba = BitmapBoolArray.GetBitmapBoolArray(b); Letter = letter; var val = GetHistogram(bba, b); XValues = val.Item1; YValues = val.Item2; }
/// <summary> /// Gets the histogram. /// </summary> /// <param name="bba">The bba.</param> /// <param name="b">The b.</param> /// <returns></returns> public static Tuple <int[], int[]> GetHistogram(BitmapBoolArray bba, Bitmap b) { var w = b.Width; var h = b.Height; var XValues = new int[w]; var YValues = new int[h]; for (var y = 0; y < h; y++) { for (var x = 0; x < w; x++) { var v = bba.bitmapBool[y][x] ? 1 : 0; YValues[y] += v; XValues[x] += v; } } return(new Tuple <int[], int[]>(XValues, YValues)); }
/// <summary> /// Gets the bitmap bool array. /// </summary> /// <param name="b">The b.</param> /// <returns></returns> public static BitmapBoolArray GetBitmapBoolArray(Bitmap b) { var w = b.Width; var h = b.Height; var bba = new BitmapBoolArray(w, h); for (var y = 0; y < h; y++) { for (var x = 0; x < w; x++) { var p = b.GetPixel(x, y); var white = p.R == 255 && p.G == 255 && p.B == 255; bba.bitmapBool[y][x] = !white; } } return(bba); }
/// <summary> /// Gets the histogram. /// </summary> /// <param name="bba">The bba.</param> /// <param name="b">The b.</param> /// <returns></returns> public static Tuple<int[], int[]> GetHistogram(BitmapBoolArray bba, Bitmap b) { var w = b.Width; var h = b.Height; var XValues = new int[w]; var YValues = new int[h]; for (var y = 0; y < h; y++) { for (var x = 0; x < w; x++) { var v = bba.bitmapBool[y][x] ? 1 : 0; YValues[y] += v; XValues[x] += v; } } return new Tuple<int[], int[]>(XValues, YValues); }
/// <summary> /// Gets the bitmap bool array. /// </summary> /// <param name="b">The b.</param> /// <returns></returns> public static BitmapBoolArray GetBitmapBoolArray(Bitmap b) { var w = b.Width; var h = b.Height; var bba = new BitmapBoolArray(w, h); for (var y = 0; y < h; y++) { for (var x = 0; x < w; x++) { var p = b.GetPixel(x, y); var white = p.R == 255 && p.G == 255 && p.B == 255; bba.bitmapBool[y][x] = !white; } } return bba; }