1 Multi-pass approach to adaptive thresholding based image segmentation Abstract - Thresholding is still one of the most common approaches to monochrome image segmentation. It often provides sufficient accuracy and high processing speed. A problem to be solved in a specific application is automated threshold selection. Generally speaking, we can make a choice between algorithms that find the threshold globally (i.e., for the whole image and those that find it locally (i.e., for each pixel separately. As the building bricks in our work we chose two classical methods: simple image statistic (SIS for global threshold evaluation, and the Bernsen method for local thresholding. The original Bernsen works fine as long as the pixel neighborhood window size is set properly. The window should fit the size of objects existing in the image. As far as it is possible to predict the object dimensions, and all of the objects are nearly equal, it is not a major drawback. The novelty of our technique is to classify the pixels in several Bernsen passes, with increasing neighborhood window. Some pixels have to be selected using global threshold value estimated by the SIS measure. Both window size and the number of passes are estimated automatically. We validate experimentally our algorithm on artificial and natural images. The proposed method not only offers good image quality, but is also quite fast. Keywords image binarization, local thresholding I. AUTOMATED THRESHOLD SELECTION METHODS Thresholding based image segmentation requires finding a threshold value τ that establishes the border between graylevel image range corresponding to objects and a range equivalent to background. After thresholding the graylevel image is converted to binary. There exist algorithms that use more than one threshold values (multithresholding, which enables to assign pixels to one of a few classes instead of just two. Threshold value(s may be entered manually or automatically. A thorough survey over automated image thresholding selection can be found in [1]. Here, the revision of techniques is presented in a compact form of taxonomy scheme (Fig.1. For further consideration we have chosen two algorithms: simple image statistic (SIS [2] for global threshold selection and locally adaptive Bernsen s method [3]. Our intention was to develop a hybrid, multi-pass algorithm that preserves only the advantages of existing methods and remains reasonably fast. Bernsen s method and SIS, compared to other algorithms, are simple to implement and speed-optimize. In the Bernsen algorithm each pixel is considered with its surrounding (usually square window W (eq. 1: Wojciech Bieniecki and Szymon Grabowski ( (1 x, y I y i < b x j b W ij = : < Wojciech Bieniecki and Szymon Grabowski are with Computer Engineering Dept., Technical University of Lodz, Poland, e-mail: wbieniec@kis.p.lodz.pl; sgrabow@kis.p.lodz.pl Entropy based: Pun Kapur Li Shanbak Yen Brink Sahoo Cheng Locally adapted threshold: Yasuda White Niblack Benrsen Palumbo Yanowitz Kamel Ob Sauvola Clustering: Riddler Otsu Lloyd Kittler Yani Yawahar AUTOMATED THRESHOLDING Pixel correlation: Pal Abutaleb Chang Beghdadi Friel Grayscale histogram analysis: Rosenfeld Sezan Carlotto & Olivo Ramesh Guo & Kai Object attributes: Tsai, Cheng Hertz O Gorman Huang Pikaz Leung Fig. 1. Taxonomy of thresholding algorithms As a local threshold the mean value of the maximum and the minimum pixel intensity within W (eq. 2 is taken: T = 0.5[max w ( I ( i + m, j + n + min w ( I ( i + m, j + n] = (2 = 0.5[ I high + I low ] Additionally, the contrast for the search window for pixel i, is defined (eq. 3: ( C = I I high If C is not sufficient (experimentally set threshold value usually for images of global contrast 255 it is set as 15 the threshold value from (5 is replaced by a global value τ 0. This value must be set a priori. Although it may be set manually, we decided to obtain it by an algorithm for adaptive threshold selection. As stated before, we use SIS. Let us assume that the perfect image presents objects with intensity a over the background with intensity b, and because of some light and material non-uniformity the intensity values are in some extent distorted the noise is introduced to image pixels. Despite of this the best threshold that discriminates the objects from background is τ = ( a + b 2. For each image point p with intensity l, let us define its gradient module (eq. 4: low (3
e = p = (4 = max l( i 1, l( i + 1,, l j 1 l j + 1 Then we may state the optimal threshold value as τ m n l e i= 1 i= 1 0 = m n i= 1 i= 1 e II. BERNSEN: PROS AND CONS The Bernsen algorithm is fairly fast, because it does not need any histogram computation. On the other hand, considering each point with its neighborhood window is adverse for speed; a common drawback of all spatial filters. The time complexity can be expressed as O(nr 2, where n is a number of image pixels and r is the radius of the neighboring window W. Assuming that W is a square with radius r, it is possible to increase the processing speed, see Fig. 2. current row i j, max(, min( (5 Window diameter Fig. 2. Speed optimization for the Bernsen s algorithm For the current row i we consider an image strip as wide as W is. For each column j we calculate minimum and maximum intensity and put them in two tables. Then we scan the row once again together with some ranges of created tables. Maximum and minimum value is selected from the tables and compared with current pixel intensity using (eq. 2. This allowed to reduce the computational complexity to O(n2r. Regarding the way of local threshold selection, Bernsen s method has a significant drawback. The window W size should fit the size of expected objects (shapes of fairly uniform intensity in order to perform the correct segmentation, thus it must be set experimentally before running the actual Bernsen routine. If the image contains objects of wide size range or the object scale is unknown, the segmentation fails. With a too large window the method works slow and tends to misclassify small objects with low contrast to background, especially when they are located near bigger objects with better contrast. This phenomenon is illustrated in Fig. 3a. Let us assume that the image contains two uniform objects O 1 and O 2, with intensities 60 and 10, respectively, and the background intensity is 100. For the window W of the point p(i, we have I max =100, I min = 10, so the mean is 55. Because this 2 value is less than O 1 intensity, pixel p(i, is incorrectly classified as belonging to the background. Small window range can cause incorrect border detection of large objects and incorrect identification of large objects. If the objects and background visible in Fig. 3b have been in distorted by noise (resulting in contrast increase inside the object, then the contrast condition (eq. 3 is satisfied for each point. In such a case some object pixels are misdetected as background (pixels brighter than the mean value. a O 1 W O 2 p(i, b O 1 O 2 p(i, Fig. 3. A case when Bernsen fails. Explanation in text. III. MULTI-PASS ALGORITHMS Our first multi-pass algorithm performs thresholding in n (n>1 steps. In each step (Fig. 4 some pixels are classified on the base of pixel intensity and information from their local neighborhood. Other pixels are passed to the next step, in which the neighborhood is enlarged. The algorithm terminates when all pixels are classified or the window size reaches the maximum. Partially segmented image 1 Partially segmented image 2 Partially segmented image n-1 Input image Step 1 (K 1 Step 2 (K 2 Step n (K n Binary image W Fig. 4. Multi pass segmentation algorithm scheme Below our multi-pass Bernsen is described. Initially all pixels are classified as background. Using SIS optimal threshold and contrast are calculated. In each iteration the window size is doubled. For increasing the speed, for the next iteration step we select only these pixels that belong to background class. The pseudocode is presented in Fig. 5.
3 In the second version of the multi-pass algorithm we perform window growing individually for each pixel. Initially the pixel belongs to background. The Bernsen procedure is repeated for increasing window size until a pixel is assigned to an object class or the radius of the window reaches its maximum. Minimum and maximum searching for a neighboring window cannot be optimized in a way presented in Fig. 2. Instead of this we use the fact that the window grows, and consequently that for a bigger window we don t have to inspect all its pixels. (T 0, C 0 := SIS(I r := R min n := 0 I n := I Objects := Background := while(r<r max foreach(p I n T := Bernsen(p, r; if(l(p<t I n+1 := I n \ p; Objects := Objects p; n := n + 1; r := 2 * r; Background := I n In the experiment we have done the following tests: - rough segmentation accuracy evaluation; - time complexity measurement for different masks for individual algorithm version - time complexity comparison. Fig. 7 presents image binarization variants for an artificial image test. a b c d Fig. 5. Multi pass v.1 algorithm pseudocode (T 0, C 0 := SIS(I Objects := Background := foreach(p I Background:=Background p; r := R min W 0:= n := 1 repeat W n:=(x,y: p-(x,y <r\w n-1 T:=Bernsen(W n if(l(p<t Background:= Background \p Objects := Objects p r:=2*r inc(n until(p Objects OR r=r max Fig. 6. Multi pass v.2 algorithm pseudocode IV. ALGORITHMS VERIFICATION For the test we have chosen 5 images of natural scenes and 5 microscopic images of immunological reaction ELISPOT. All pictures were taken by a digital camera. Fig. 7. Segmentation results for an artificial image test (a. (b Bernsen with big mask, (c Bernsen with small mask, (d multi-pass algorithm. Fig. 7b shows the Bernsen binarization with the mask size comparable to the object in the center. The contour has been marked to show segmentation results. As explained in Fig. 3 this object is too bright to be accurately segmented. Fig. 7c shows Bernsen s binarization results for a small mask. It is clearly visible that the internal part of each object has been classified as a background, both for bright object and the object in the left with high contrast interior. For a multi-pass algorithm v.1 all objects have been segmented correctly. Next, one ELISPOT image was used for a comparison. The original image (Fig. 8a contains spots that should be extracted from background. The image size was 800 x 800 pixels. Spots have different size and intensity. In Fig. 8b we show the result of SIS binarization. Not all spots have been extracted and there are artifacts caused by non-uniform lighting. Fig. 8c presents Bernsen binarization with mask 40. The number of identified spots increased, but still some of them have been omitted. Figs. 8d and 8e show the result of multi-pass algorithm v.1 and v.2 with mask range [5 40]. V.1 version did the most accurate segmentation. The algorithms have also been compared in the aspect of speed. All the code has been written in C++, compiled with Microsoft Visual C++ 6.0 and run on an Athlon 2 GHz. The results from Fig. 9 are average values for 10 different images.
4 No algorithm can match simple thresholding in the speed. Among the others, the fastest one is the first version of multipass Bernsen that uses strip optimization (see Fig. 2. It works faster than a single Bernsen pass, because starts from a smaller mask (here: 10, and not all the pixels have to be processed with the maximum mask (here: 40. The speed tests were performed for 5 different mask sizes independently for 3 images. The results were approximated by a continuous function that minimizes the square error. The average time complexity of Bernsen method is as O(r 2, what was predicted earlier, both optimized Bernsen and first multipass algorithm have linear complexity. The time complexity of the second version of multi-pass algorithm is significantly O r log r. worse, and the best fitted function for it is ( ( a b c Fig. 10. Time complexity as a function of mask size d e Fig. 8. ELISPOT image segmentation. Explanation in text. Fig. 9. Average processing speed (Athlon 2 GHz In the last experiment we estimated the time complexity as a function of window radius. (Fig. 10. V. CONCLUSION Multi-pass algorithms are more and more often used in image processing. We have presented an image binarization algorithm from this category, achieving competitive results both in image accuracy and processing speed. The algorithm is based on Bernsen s method, although we have greatly increased its flexibility. In particular, our method is more robust to artifacts when the objects on the image are of varying sizes and local contrast. The usefulness of the algorithm has been confirmed on a variety of natural and artificial images (from various applications, including biomedical ones. REFERENCES [1] Sankur B., Sezgin M., A Survey Over Image Thresholding Techniques And Quantitative Performance Evaluation, (accepted, Journal of Electronic Imaging, 13(1, 146-165, January, 2004. [2] Kittler J., Illingworth J. and Foglein J., Threshold selection based in a simple image statistic, Computer
5 Vision, Graphics and Image Processing, vol.30, pp. 125-147, 1985. [3] Bernsen J., Dynamic thresholding of grey-level images, Proceedings 8th International Conference on Pattern Recognition, Paris, pp. 1251-1255, 1986.