/* build cell table */ public static Cell[,] buildCellTable(Bitmap image, float threshold) { Cell[,] cellArr = new Cell[image.Width / 2, image.Height / 3]; Color color = new Color(); for (int majr = 0; majr < cellArr.GetLength(1); majr++) { for (int majc = 0; majc < cellArr.GetLength(0); majc++) { cellArr[majc, majr] = new Cell(); for (int minr = 0; minr < 3; minr++) { for (int minc = 0; minc < 2; minc++) { color = image.GetPixel((2 * majc) + minc, (3 * majr) + minr); if (color.GetBrightness() <= threshold) { cellArr[majc, majr].addDot((3 * minc) + minr + 1); } } } } } return(cellArr); }
/* build cell table */ public static Cell[,] buildCellTable(Bitmap image, float threshold) { Cell[,] cellArr = new Cell[image.Width/2, image.Height/3]; Color color = new Color(); for (int majr = 0; majr < cellArr.GetLength(1); majr++){ for (int majc = 0; majc < cellArr.GetLength(0); majc++){ cellArr[majc, majr] = new Cell(); for (int minr = 0; minr < 3; minr++){ for (int minc = 0; minc < 2; minc++){ color = image.GetPixel((2 * majc) + minc, (3 * majr) + minr); if (color.GetBrightness() <= threshold){ cellArr[majc, majr].addDot((3 * minc) + minr + 1); } } } } } return cellArr; }
/* public static Cell[,] buildCellTable(Bitmap image) { Cell[,] cellArr = new Cell[image.Width / 4, image.Height / 6]; Color color = new Color(); for (int majr = 0; majr < image.Height; majr++) { int count =0; int pixelcount =0; for (int majc = 0; majc < image.Width; majc+=2) { for (int i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { color = image.GetPixel(majc + j, majr + i); if(color.GetBrightness() < 0.5) pixelcount ++; } } if (pixelcount > 2) cellArr[majc, majr].addDot(count); switch (count) { } } } return cellArr; } */ /* public static Cell[,] resizeCell(Cell[,] Big){ int width = Big.GetLength(0)/2; int height = Big.GetLength(1)/3; Cell[,] small = new Cell[width, height]; for (int majr = 0; majr < height; majr++){ for (int majc = 0; majc < width; majc++){ small[majc, majr] = new Cell(); for (int minr = 0; minr < 3; minr++){ // for (int minr = 0; minr < 2; minr++){ for (int minc = 0; minc < 2; minc++){ int count =0; for (int i =0; i<6; i++) { if(Big[(2 * majc) + minc, (3 * majr) + minr].getDot(i)) count ++; } if(count >= 2) { small[majc, majr].addDot((3 * minc) + minr + 1); } } } } } return small; }*/ public static Cell[,] resizeCell(Cell[,] Big) { int width = Big.GetLength(0) / 2; int height = Big.GetLength(1) / 2; int smallw = 0; int smallh = 0; Cell[,] small = new Cell[width, height]; for (int majr = 0; majr <Big.GetLength(1); majr+=2) { if (majr != 0) { smallh++; } smallw = 0; for (int majc = 0; majc < Big.GetLength(0); majc+=2) { if(smallw < small.GetLength(0) && smallh < small.GetLength(1)){ small[smallw, smallh] = new Cell(); int count = 0; int curw = majc; int curl = majr; while(count < 6) { int dotcount=0; switch (count) { case 1: if (Big[majc, majr].getDot(1)) dotcount++; if (Big[majc, majr].getDot(2)) dotcount++; if (Big[majc, majr].getDot(4)) dotcount++; if (Big[majc, majr].getDot(5)) dotcount++; if (dotcount >= 1) { small[smallw, smallh].addDot(1); } break; case 2: if (Big[majc, majr].getDot(3)) dotcount++; if (Big[majc, majr].getDot(6)) dotcount++; if (Big[majc, majr+1].getDot(1)) dotcount++; if (Big[majc+1, majr+1].getDot(4)) dotcount++; if (dotcount >= 1) { small[smallw, smallh].addDot(2); } break; case 3: if (Big[majc, majr+1].getDot(2)) dotcount++; if (Big[majc, majr+1].getDot(3)) dotcount++; if (Big[majc, majr+1].getDot(5)) dotcount++; if (Big[majc, majr+1].getDot(6)) dotcount++; if (dotcount >= 1) { small[smallw, smallh].addDot(3); } break; case 4: if (Big[majc+1, majr].getDot(1)) dotcount++; if (Big[majc+1, majr].getDot(2)) dotcount++; if (Big[majc+1, majr].getDot(4)) dotcount++; if (Big[majc+1, majr].getDot(5)) dotcount++; if (dotcount >= 1) { small[smallw, smallh].addDot(4); } break; case 5: if (Big[majc+1, majr].getDot(3)) dotcount++; if (Big[majc+1, majr].getDot(6)) dotcount++; if (Big[majc+1, majr+1].getDot(1)) dotcount++; if (Big[majc+1, majr+1].getDot(4)) dotcount++; if (dotcount >= 1) { small[smallw, smallh].addDot(5); } break; case6: if (Big[majc+1, majr+1].getDot(2)) dotcount++; if (Big[majc+1, majr+1].getDot(5)) dotcount++; if (Big[majc+1, majr+1].getDot(3)) dotcount++; if (Big[majc+1, majr+1].getDot(6)) dotcount++; if (dotcount >= 1) { small[smallw, smallh].addDot(6); } break; } count++; if(count == 6){ smallw++; } } } } } return small; }
/* write output file */ public static void writeOutput(Cell[,] cellArr, Hashtable map, string fileName) { TextWriter text = new StreamWriter(fileName); for (int y = 0; y < cellArr.GetLength(1); y++){ for (int x = 0; x < cellArr.GetLength(0); x++){ text.Write(map[cellArr[x, y].getKey()]); } text.WriteLine(); } text.Close(); }
//different resize public static Cell[,] resizeCell(Cell[,] Big) { int width = Big.GetLength(0) / 2; int height = Big.GetLength(1) / 2; int smallw = 0; int smallh = 0; Cell[,] small = new Cell[width, height]; for (int majr = 0; majr < Big.GetLength(1); majr += 2) { if (majr != 0) { smallh++; } smallw = 0; for (int majc = 0; majc < Big.GetLength(0); majc += 2) { if (smallw < small.GetLength(0) && smallh < small.GetLength(1)) { small[smallw, smallh] = new Cell(); int count = 0; int curw = majc; int curl = majr; while (count < 6) { int dotcount = 0; switch (count) { case 1: if (Big[majc, majr].getDot(1)) { dotcount++; } if (Big[majc, majr].getDot(2)) { dotcount++; } if (Big[majc, majr].getDot(4)) { dotcount++; } if (Big[majc, majr].getDot(5)) { dotcount++; } if (dotcount >= 1) { small[smallw, smallh].addDot(1); } break; case 2: if (Big[majc, majr].getDot(3)) { dotcount++; } if (Big[majc, majr].getDot(6)) { dotcount++; } if (Big[majc, majr + 1].getDot(1)) { dotcount++; } if (Big[majc + 1, majr + 1].getDot(4)) { dotcount++; } if (dotcount >= 1) { small[smallw, smallh].addDot(2); } break; case 3: if (Big[majc, majr + 1].getDot(2)) { dotcount++; } if (Big[majc, majr + 1].getDot(3)) { dotcount++; } if (Big[majc, majr + 1].getDot(5)) { dotcount++; } if (Big[majc, majr + 1].getDot(6)) { dotcount++; } if (dotcount >= 1) { small[smallw, smallh].addDot(3); } break; case 4: if (Big[majc + 1, majr].getDot(1)) { dotcount++; } if (Big[majc + 1, majr].getDot(2)) { dotcount++; } if (Big[majc + 1, majr].getDot(4)) { dotcount++; } if (Big[majc + 1, majr].getDot(5)) { dotcount++; } if (dotcount >= 1) { small[smallw, smallh].addDot(4); } break; case 5: if (Big[majc + 1, majr].getDot(3)) { dotcount++; } if (Big[majc + 1, majr].getDot(6)) { dotcount++; } if (Big[majc + 1, majr + 1].getDot(1)) { dotcount++; } if (Big[majc + 1, majr + 1].getDot(4)) { dotcount++; } if (dotcount >= 1) { small[smallw, smallh].addDot(5); } break; case6: if (Big[majc + 1, majr + 1].getDot(2)) { dotcount++; } if (Big[majc + 1, majr + 1].getDot(5)) { dotcount++; } if (Big[majc + 1, majr + 1].getDot(3)) { dotcount++; } if (Big[majc + 1, majr + 1].getDot(6)) { dotcount++; } if (dotcount >= 1) { small[smallw, smallh].addDot(6); } break; } count++; if (count == 6) { smallw++; } } } } } return(small); }