Optimization of the Fast Image Binarization Method Based on the Monte Carlo Approach

1 Abstract —The paper concerns the problem of fast image processing in the low computational power systems with limited memory, which are typical for robot vision and embedded systems. Assuming the necessity of decision based on incomplete information when the amount of visual data is too big for an efficient processing, the reduction of their amount becomes a crucial element of the processing system. A good classical example may be histogram based image binarization which requires the knowledge of the distribution of intensities for the whole grey-scale image. Applying the Monte Carlo method for the reduction of the amount of data, much smaller images with similar statistical properties may be obtained, which can be further used for thresholding and binarization e.g. using Otsu algorithm. A relevant problem in this approach is the proper choice of the number of samples for the Monte Carlo method which influences the result of binarization. In this paper the method based on the analysis of image entropy or energy changes is proposed for this purpose. Obtained results, verified for various images, are promising even for relatively small number of samples used for the estimation of the histogram.


I. INTRODUCTION
Image binarization is one of the most critical algorithms influencing the results of further analysis conducted using obtained binary images.Probably the most popular area of application of such images is related to automatic document analysis using Optical Character Recognition (OCR) methods which can be a difficult task in the presence of noise or strong degradation of image quality influencing the readability of the text.
Apart from the OCR applications, binary images can be successfully utilised in many applications based on low computational complexity solutions (often with limited amount of memory), some embedded systems, autonomous robots, intelligent vehicles or unmanned aerial vehicles (UAVs) etc.In many of such applications the analysis of binary images can be treated as a "natural" solution, e.g. for line following robots, whereas some other systems may utilise binary images for fast preliminary analysis purposes.
Although some classical binarization algorithms are typically used such as well-known Otsu algorithm [1], the problem of image binarization can be found still open for Manuscript received November 16, 2013; accepted February 26, 2014.
new algorithms as it is not always simple for all images.One of the challenges in this field is related to the binarization of text documents subjected to distortions typical for old, historical documents containing many types of artefacts.As some distortions may also be introduced during the acquisition of such images, they may play an important role influencing the results of binarization and further character recognition, especially for high resolution images.
Nevertheless, in many applications there is no need to analyse the whole high resolution image assuming further analysis of binary image which is very fast especially in comparison to colour images.Since the conversion into binary image typically requires the analysis of all pixels of the original image, it may be a bottleneck of the processing algorithm especially in real-time systems, e.g.mobile robots.

II. MOTIVATION
The idea presented in the paper is based on the assumption that using the reduced amount of data from the reference image it is possible to approximate the threshold values using for image binarization with acceptable accuracy decreasing highly the computational effort.For comparison purposed the results obtained using classical Otsu method are used.
However, the difference between the approximated threshold values and the Otsu threshold is not necessarily the best method for evaluation of results.The main problem limiting the possibilities of performance evaluation of binarization algorithms is the availability of the "groundtruth" images since the proper result of binarization is not always obvious [2], [3].Unfortunately, among various image databases built for many purposes including image quality assessment, segmentation, texture classification, evaluation of the CBIR methods etc., the binary images and their colour or grey-scale equivalents are not common.In order to evaluate various binarization methods relatively small, but generally accepted by the community, datasets developed for Document Image Binarization Contests (DIBCO), may be used.These contests are organized each year by a group of Greek researchers involved in text recognition algorithms [4].For our experiments the latest dataset containing 16 images (8 with handwritten documents and 8 with machine printed ones) has been used.For the numerical computations method, as presented in the paper [6], and can be decreased using the optimization of the fast Otsu binarization method proposed in the remaining part of the paper.

A. Application of the Monte Carlo Method
The basic version of the fast method of binarization proposed by authors and further analysed in this paper is on the construction of the approximate histogram of the image using the Monte Carlo method.Drawing the specified number of elements representing image pixels (reshaped into one-dimensional vector in order to avoid two independent draws for the numbers of rows and columns), assuming the use of the random numbers generator with uniform distribution, a simplified representation of the image can be obtained as the result of the statistical experiment.Its histogram can be then used for determining the Otsu threshold which is approximated using only n drawn pixels from N elements of the image.Such determined threshold can be used for the binarization of the input image.

B. Verification of the Method
Since the statistical experiments have been conducted several times for various numbers of drawn pixels, the obtained results of the approximated threshold depend on the number of draws.For all images from the DIBCO2011 the increase of the number of pixels leads to the decrease of the approximation error.Nevertheless, the threshold values may be lower or higher than the value calculated using Otsu method what is illustrated in Fig. 1 for an exemplary image with handwritten text (HW1).Comparing the obtained results for highly demanding and challenging images included in the DICOM dataset, two sources of binarization errors can be identified.The first one can be considered as related to the method since Otsu binarization not always leads to the results consistent with "ground-truth" images as illustrated in Fig. 2.However, due to the universal character of the method, it has been used as a reference.The second part of errors is the consequence of the reduced number of analysed pixels in the Monte Carlo method, as presented in the paper [6], and can be decreased using the optimization of the fast Otsu binarization method proposed in the remaining part of the paper.

A. Remarks on the Computational Effort
The main goal of the approach proposed in the paper is not related to the increase of the binarization performance by means of the consistency with "ground-truth" images but increase of the processing speed obtaining results similar to classical Otsu method with acceptable error level.Since many more sophisticated binarization methods have been proposed during several last years, including Sauvola's algorithm [7], adaptive Otsu method [8] and multi-scale frameworks [9], it is worth to notice that their computational complexity is much higher than for Otsu algorithm.For this reason, the approach presented in this paper may also be adapted in future for some of those algorithms on order to decrease their computational effort.
Since the strong reduction of the number of pixels using the Monte Carlo method may lead to errors of the threshold approximated values, the direct usage of very small number of draws may lead to improper results.In order to improve the proposed method without significant increase of the processing time, several calculation steps with growing number of drawn pixels may be used with three possible stop criterions based on estimated energy of the image, its estimated entropy and changes of the approximated threshold.

B. Estimation of Image Energy and Entropy
Results of the image binarization depend strongly on the image contents which can be described not only using the histogram but also by some other quantities.In the paper an iterative approach is proposed which utilizes the energy and entropy of the image estimated using only the drawn pixels according to the Monte Carlo method.The energy of the image can be estimated using the histogram H calculated for the simplified representation of the image containing only n drawn pixels as where b denotes the histogram bin (each of L luminance levels for grey-scale image).
Similarly, the image entropy can be estimated as In the proposed optimization of the fast Otsu binarization method a number of iterations is conducted assuming the increased number of drawn pixels (n) for each iteration.For each iteration the energy and entropy are estimated as well approximated Otsu threshold.Calculations should be stopped after the detection of one of three situations:  local maximum of the estimated energy,  local minimum of the estimated entropy,  three consecutive approximated threshold differing by less than 0.02.For verification purposes the energy and entropy of the original image as well as Otsu threshold have been calculated for the whole DICOM2011 dataset (16 images).Obtained results for two different images together with correct results are presented in Fig. 3 and Fig. 4. Images have been chosen intentionally as an "easy" and "hard" one (HW1 and PR7 respectively).Illustration of the difficulties and challenging character of the PR7 image is shown in Fig. 5 containing the original image, "ground truth" and approximated threshold values.As can be observed in Fig. 3 and Fig. 4 for both images the local maximum of the energy as well as the local minimum of the estimated entropy can be easily determined.The same phenomenon can be observed for all tested images therefore it can be used as the stop criterion assuming the minimum required number of drawn samples using the Monte Carlo method ensuring the proper threshold estimation with acceptable error level not influencing the quality of the binary image.
For HW1 image both criteria are fulfilled for n = 80 randomly chosen pixels whereas for PR7 image local maximum of energy can be found for n = 150 points and local maximum of entropy for n = 50 drawn pixels.
It is worth noticing that all the images in the DIBCO2011 dataset have different resolutions and different amount of useful data (defined as a fill factor for "ground truth" binary images presented in Table I).

V. EXPERIMENTAL RESULTS
Application of the proposed solution decreases significantly the number of analysed pixels.For example assuming the stop criterion fulfilled for n = 150 points, being equivalent to only about 0.044 % of pixels of PR7 image, even the calculation of all previous steps requires altogether not more than 1 % of all pixels.However, the results obtained using two stop criteria based only on the estimated energy and entropy (values presented in Fig. 7) are not always satisfactory, leading to unacceptable high threshold error, especially for images with low fill factor.
Finally, the stop criterion has been defined as the three consecutive approximated threshold values differing by less than 0.02, but for higher number of drawn samples than determined for the first local maximum of the estimated energy and the first local minimum of entropy.The idea of the stop criterion is illustrated in Fig. 6 presenting the results obtained for PR7 image.Nevertheless, the results obtained for this image are not correct, as presented in Fig. 8 -the three consecutive values of the threshold differing by less than 0.02 have been obtained for n = 200, n = 300 and n = 400 samples leading to improper threshold value.
The results obtained for some other images from the analysed dataset are presented in Fig. 9 where the last column contains the results obtained applying the proposed stop criterion for the fast Otsu method.The results are presented for the following images (from top): HW7 for n = 1000, HW8 for n = 300, PR6 for n = 200 and PR8 for n = 600 respectively.Values of performance metrics [5] obtained for PR6 and PR8 images are the same as for Otsu method so they are not included in Table II presenting only the results obtained for HW7 and HW8 images.

VI. CONCLUSIONS
The results obtained for 15 images from the dataset (except PR7) are very similar to the effect of applying Otsu algorithm for the whole image, as illustrated in Fig. 9 and Table II.It leads to some conclusions concerning the applicability of the proposed method limited to the images with relatively high fill factor.As can be easily noticed in Table I, only PR7 image can be characterised by extremely low percentage of samples representing the useful data (only 2.5 % of pixels) what is the main limitation for the Monte Carlo method, especially using strongly reduced number of samples.
Binarization of images with large background areas using the proposed approach is difficult due to the uniform distribution of the random number generator applied in the Monte Carlo method.Since a large number of drawn points represent the background information, the proper choice of the threshold value in the Otsu algorithm may be troublesome.Nevertheless, the results obtained for the images with more uniformly distributed useful data on the image with higher fill factor are promising and may be a starting point for further applications of the proposed approach with more complicated image binarization and segmentation algorithms.

Fig. 1 .
Fig. 1.Approximated threshold values obtained using fast Otsu method obtained for the image HW1.

3 . 5 .
Energy (a) and entropy (b) estimated for the HW1 image.a) b) Fig. 4. Energy (a) and entropy (b) estimated for the PR7 image.Original input image PR7 (a) with "ground truth" (b) and results of threshold approximation (c) for different numbers of drawn pixels.

Fig. 6 . 8 . 9 .
Fig. 6.Idea of the stop criterion for optimization of the proposed method.

TABLE I .
PARAMETERS OF THE IMAGES FROM DIBCO2011DATASET.

TABLE II .
VALUES OF BINARIZATION PERFORMANCE METRICS FOR THE SELECTED IMAGES FROM DIBCO2011 DATASET.