Skew Detection and Correction Technique for Arabic Document Images Based on Centre of Gravity

: Problem statement: Skew detection and correction is the first step process in the document analysis and understanding processing steps. Correction the skewed scanned document image is very important, because it has a direct effect on the reliability and efficiency of the segmentation and feature extraction stages. The noises and the deviation in the document resolution or types are still the main two challenges facing the Arabic skew detection and correction methods. Approach: The proposed method work involved inscribing the text in the document by an arbitrary polygon and derivation of the baseline from polygon’s centroid. Results: The proposed method was implemented on 150 different scanned Arabic documents, from different sources like journals, textbooks, newspapers and the like in addition to handwritten document, with different resolutions and different fonts and it was obtained an accuracy ratio of 87%. Conclusion: The proposed method was efficient, simple and fast, it was not affected by noise and it was proved their suitability to work with documents with different fonts and documents with different resolutions.


INTRODUCTION
The goal of the character recognition systems is to transform the input data (pattern of data), such as text written document on manuscript, text typed on document or online writing into a digital format. This can be manipulated by word processing software [4,13] . Recognition can be done offline or online. In offline recognition, papers, manuscripts or documents are scanned or captured and finally are manipulated by OCR system. In online recognition application takes place during the writing process [2,7,9,19] .
Arabic language is generally considered universal as its letters are the basis for various other languages like Urdu, Farsi, Jawi and many others languages [3] . Arabic character recognition system is considered quite complex as compared to Latin and Chinese because the text is written cursively and also the complexity of the alphabets representation in Arabic [19] . The Arabic OCR system goes through five stages: Image acquisition, Preprocessing, Segmentation, Feature Extraction and Classification (Recognition) [2,7,9,16] . These stages work together to improve OCR systems recognition ratio moreover to reduce the recognition time [13,14] .
Arabic OCR preprocessing stage should contain smoothing, noise removal, image decomposition, skew detection and correction, edge detection and baseline detection, the document skew detection and correction is that research's focus.
The skew correction is considered mandatory in preprocessing Arabic OCR system stage, because it has a direct effect on the reliability and efficiency of the segmentation and feature extraction stages. As skew is generally introduced into the image while scanning and leaving it as it is without correction will give wrong results during document analysis and recognition [10] . Figure 1 shows one of the skewed document images. Both Hough transform, Cross Correlation, Projection Profile, Fourier transform and K Nearest Neighbor (K-NN) clustering were used for skew detection and correction the scanned images.
Hough transform [15] is also used for skew detection. The points in the Cartesian coordinate system are described as a summation of sinusoidal distribution: The skew angle is calculated on the basis that at the skew angle the density of Transform spaces is maximum. After mapping (x, y) into (p, θ), the count of points where a sinusoidal curve intersects another sinusoidal curve with a different (p, θ) value increases the probability that a line determining the skew angle. A lot of research has been carried out on using Hough transform for determining skew angle. In [8] , a selected area of the document is chosen for skew angle determination. The reason for choosing a particular area is to reduce the input data to process as the computational complexity in this process is quite high. A few other methods like hierarchical Hough transform [18] whose computational complexity is also high, another method with less computational complexity using hierarchical Hough transform [8,12] have already been proposed.
Cross correlation [17] is a computation intensive approach which is quite accurate. The lines of text in a document are considered as vertical lines which are spaced with a uniform distance of d between them. The skewed document vertical lines subtend an angle with the horizontal. So pixels in these vertical parallel lines are translated due to skewing. This translation concept is used for finding the correlation as: R(x 0 , s) = ∑ y L 1 (x 0 , y) L 2 (x 0 +d, y+s) (2) where, L1 and L2 are the parallel vertical lines.
The main drawback is that in real scanned document d is not constant and often needs to be backtracked.
Horizontal projection profile [6] is generally a histogram of the number of dark pixels in horizontal scan lines of a document. The troughs and Peaks are calculated as for a script with horizontal text lines the projection have peaks at text line positions and troughs at locations between successive text lines. The difference between the trough and peak is calculated at every angle and the maximum difference gives the skew angle. Method discussed in [1] is a unique method in which the document is partitioned into vertical strips and the Horizontal projection profile is applied to each strip individually which are later correlated to determine skew angle. This method is particularly good in determining small skew angles (less than 100).
The Fourier Transform method [10] works on the basic principle that skew angle is the one at which density of spectrum is largest for the document. However, the computational complexity is high.
Another computationally intensive method is the clustering method. In [5] , the skew angle for all the connected words in the document is found out and a histogram for the determined skew angles is realized. The maximum clustered skew angle in histogram is the skew angle of the document. In another method [11] , the centers of the nearest neighbors of the connected words in the document are vectorised and later correlated to determine the skew angle.
Revealing the importance of this stage the author of this study mainly concentrates on the Skew angle determination sub process of this stage and implements a novel algorithm in this research.

MATERIALS AND METHODS
The text image which is scanned at an angle can be rotated to a normal position following a series of steps. As a starting point an Arabic text image which is scanned in an abnormal direction is considered. The steps to be followed for getting back to the normal position include: • Base line identification • Skew angle correction The baseline identification is generally the most important step of the whole process. Baseline is the Line along which the center of gravity of the word hangs. A novel Approach is used in this algorithm where in the whole word is inscribed in a polygon with at least two dimensions. The centre of gravity of the polygon is considered as a single line extending a certain angle with the horizontal. The angle is measured which gives the angle by which the word or document is rotated and also signifies the direction and angle by which is should be rotated for it to be a text in readable and normal form.

Centroid:
The centroid is also known as the "centre of gravity" or the "center of mass". The position of the centroid assuming the polygon to be made of a material of uniform density is given below. In Fig. 2, a 6 side polygon is shown and the Center Of Gravity (COG) is calculated using the equation: After calculating the COG point, a line is drawn joining the origin and the COG which is the required line of gravity.
Using a rectangle as the polygon is described here. The centroid for a rectangle is the point joining the diagonals which is considered as line of gravity for the polygon. Consider the document in Fig. 3 below which is skewed. Inscribe the text document in a rectangle by considering the farthest pixel in the four directions and determine the centroid. The line joining the centroid and the origin is the required baseline which gives the skew angle.
Although a rectangle is used as polygon for explanation in this case, the implemented algorithm uses an ellipse as polygon because of the simplification that the baseline for the ellipse is the major axis itself which reduces the computation.
The proposed algorithms steps: Input: Text Image, like the samples showing in Fig. 4.

Output:
Skew corrected text image, like the samples showing in Fig. 5.
Step 1: Determine the farthest points in all the four directions. Figure 6 shows the scanned image farthest points.
Step 2: Find the centroid using these four points, so the previous four points representing the polygon corners and the polygon center (COG), can be calculated by using the equations number three. Figure 7 shows the COG. Step 3: To get the baseline, Join the centroid to the origin, Fig. 7 shows the scanned image baseline and the COG too.
Step 4: Find the angle of the so formed baseline which gives the skew angle. Figure 8 shows the skewed angle detection.

Fig. 8: The skewed angle detection
Step 5: Rotate the document in the reverse direction (clockwise direction) by the skew angle.

RESULTS
The method has been implemented in the math lab programming language on duo core 2.0 GHZ in 2009. We have considered different skewed documents from different sources like journals, textbooks, newspapers and the like in addition to handwriting document. For experimentation purpose 150 documents are considered, half of them are handwriting documents, samples of text documents are shown in Fig. 4. The correct skewed angle and the result skewed angle obtained by using the proposed method, in addition to the computing time taken by the proposed method for these documents are reported in Table 1. Figure 5 shows the corrected text image after applying the proposed method of images reported in Fig. 4.

DISCUSSION
In the skew detection and correction algorithms, the simplicity, generality and the applicability of the proposed method can be discussed, so the proposed method works with both the handwritten and the printed documents, by using the same procedures, while in other hand each of the Hough transform and Projection Profile can work with both types of documents, whether printed or handwritten, but the results remain poor unless it is supported by some of the conditions for working with each method on its own. The proposed method also is proved that working with the printed documents is better than the handwritten documents, because of the nature of the Arabic language handwritten and this can be solved by surrounding the text of the document with eight points, two points in each direction.
Also the proposed method can find the skewed angle of deviation of the different kinds of printed documents such as magazines or books and other printed documents, as shown in Fig. 4 a and b, as well as handwritten documents, as shown in Fig. 4 d-f. And it is able to work with documents with different resolutions, as shown in Fig. 5. While on the other hand, other methods usually are designed to find a deviation skewed angle of a certain type of documents with resolutions constant. The noise does not affect the proposed method performances, while it has very high influences in them, basing on the Hough transform and Projection Profile.

CONCLUSION
An efficient, simple and fast a novel and accurate method to estimate skew angle is presented in this study. The proposed methods work based on Centre of Gravity. After surrounding the text of the document with four points which represent the four corners for the production of parallelogram. Proposed method has proved it can find the angle of deviation of the different kinds of printed documents such as magazines or books and other printed documents, as well as handwritten documents. Proposed method also proved their suitability to work with documents with noise and documents with different resolutions. Proposed method was implemented on 150 different documents and the rate of accuracy was 87% and it is proved that working with the printed documents is better than the handwritten documents.