Research Article
MyOcrTool: Visualization System for Generating Associative Images of Chinese Characters in Smart Devices
Program Listing 2
Program Listing 2: The program listing of iterative method for calculating the threshold.
Input: grayImage | Output: threshold | private static int getIterationHresholdValue (int minGrayValue, int maxGrayValue) { | int T1; | int T2 = (maxGrayValue + minGrayValue)/2; | do { | T1 = T2; | double s = 0, l = 0, cs = 0, cl = 0; | for (int i = 0; i < imgHeight; i++) { | for (int j = 0; j < imgWidth; j++) { | int gray = imgPixels[imgWidth ∗ i + j]; | if (gray < T1) { | s += gray; | cs++; | } | if (gray > T1) { | l += gray; | cl++; | } | } | } | T2 = (int) (s / cs + l / cl) / 2; | } | while (T1! = T2); | return T1; | } |
|