4、间的灰度全部变成255,其它的变成0。这里我采用的是网上广为流行的自适应二值化算法。Code 1 public static void Binarizate(Bitmap map) 2 { 3 int tv = ComputeThresholdValue(map); 4 int x = map.Width; 5 int y = map.Height; 6 for (int i = 0; i < x; i++) 7 { 8 for (int j = 0; j < y; j++) 9 {10
6、20 }21 22 private static int ComputeThresholdValue(Bitmap img)23 {24 int i;25 int k;26 double csum;27 int thresholdValue = 1;28 int[] ihist = new int[0x100];29 for (i = 0; i < 0x100; i++)30 {31 ihist[i] = 0;32 }33 int gmin = 0xff;34 i
7、nt gmax = 0;35 for (i = 1; i < (img.Width - 1); i++)36 {37 for (int j = 1; j < (img.Height - 1); j++)38 {39 int cn = img.GetPixel(i, j).R;40 ihist[cn]++;41 if (cn > gmax)42 {43 gmax = cn;44