Some algorithms for optical character recognition compare a scanned image with templates of "perfect" characters. Part of the difficulty with such comparisons is deciding where to start the comparison. This is because the characters in the scanned image are subject to noise and distortion, resulting in changes in size, position, and orientation. A procedure that is sometimes used to deal with changes in position matches the "center of gravity" of the scanned character and the templates against which it is compared. In this problem you are to determine the "centers of gravity" of scanned images of characters.
For our purposes, a scanned image will be a rectangular array of real numbers, each of which represents the gray-scale value of a point in a scanned image. Each gray-scale value will be between 0 (representing a totally white region) and 1 (representing a totally black region). The array will have no more than 25 rows and 25 columns.
The center of gravity is a particular element of an array. Suppose a center of gravity is in the ith row and jth column. Then the difference between the sum of the elements of the two array portions above and below the ith row is minimal. Likewise, the difference of the sums of the elements in the two array portions to the left and to the right of the jth column is minimal.
Consider the array shown below, which might have resulted from scanning a lower case "o." The center of gravity for this array is uniquely in row 3, column 3. The difference of the sum of the elements in each array portion formed by ignoring the third row is 0.1 (the sums are 5.55 and 5.65). The difference of the sum of each array portion formed by ignoring the third column is 0.0 (the sums are both 5.60).
5 5 0.1 0.2 0.1 0.2 0.1 0.1 0.2 0.3 0.1 0.1 0.2 0.3 0.1 0.1 0.3 0.4 0.1 0.1 0.1 0.2 0.2 0.2 0.3 0.3 0.1 5 10 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.6 0 0
Case 1: center at (3, 3) Case 2: center at (4, 6)