Você está na página 1de 4

# World Congress on Software Engineering

## A Fast Algorithm for Erosion and Dilation in Mathematical Morphology

Xiaoping Lina, Zhihong Xub a Faculty of Computer, Guangdong University of Technology, Guangzhou, 510006, P. R. China b SierraAtlantic (Guangzhou) Software Development Co. Ltd. , Guangzhou, 510663, P. R. China xiaopinglingdut@163.com Abstract
A fast algorithm for local maximum and minimum filters is presented by Marcel van Herk, utilizing separability and recursive algorithms. In this paper, we put forward another improved algorithm based on Marcel van Herk s research. The new algorithm makes the comparison for each pixel in two auxiliary spaces without utilizing the original image space with the purpose of reducing the calculation for the space. A better result has been obtained based upon the computer simulation, and the method, which is more suitable for implementation of programming, is capable of improving the efficiency of the operation for erosion and dilation. Keywords: Mathematical Morphology, erosion, dilation, van Herk algorithm micrograph analysis, Medical images processing, Industrial detecting, Robert visual etc. Among the operation of Mathematical Morphology, erosion and dilation is the base of other complicated operations implementation. When using complicated functions to process images, the scanning operation will cost considerable time and space spending, thus slowing down the processing speed. Because of this, the efficiency of algorithm will be the decisive factor especially in those images processing which requires rigor time spending and large space [3,4]. Therefore, further research on how to improve the efficiency of these two elementary operations becomes necessary. Marcel van Herk algorithm successfully realized morphological erosion (dilation) without concerning of the structure elements length. It fixes the comparing times of the pixel value of every pixel to 3, which greatly accelerates the erosion (dilation) process [5]. But still there are three aspects of deficiencies in van Herk algorithm: Only odd-length structure elements are available. It costs more time in processing for the sake that it needs horizontal move of g(x) and h(x) when counting pixel values of every row (column). It needs two extra auxiliary spaces whose length of line (row) must be exactly the same as the image. As a result, it cost considerable space when dealing with large-size images. Consequently, in this paper, we focus on the existing deficiencies of van Herk algorithm, meanwhile attempt to create an improved algorithm based on it.

1. Introduction
Mathematical Morphology mainly serves for getting object topological figure and result information. It reaches the essential configured shape of an object by some operation on interaction between object and structure element. The application of Mathematical Morphology can simplify the data of images, meanwhile remains their fundamental figure features and delete the unconcerned structure [1,2]. The application of Mathematical Morphology in graphics processing include: Uses morphological fundamental operation to observe and process graphics on purpose of ameliorating the quality of images. Describes and defines various geometrical parameter and characteristics, such as area, perimeter, connectivity, granule, skeleton and direction etc. Computer text identification, Computer
978-0-7695-3570-8/09 \$25.00 2009 IEEE DOI 10.1109/WCSE.2009.367 185

## 2. Van Herk Algorithm

Erosion (dilation) with van Herk algorithm, only 3 times of comparing of each pixel value in one image is required, and it doesnt care about the length of structure element. Therefore, as to two-dimensional

rectangle structure elements, merely 6 times of pixel value comparing is required. Erosion (dilation) with van Herk can boost the speed of process to a great extent in the condition of long-length structure element operation [6]. Formulas of van Herk algorithm are below. The following notions are showed: f(x), g(x) and h(x) represent discrete images or structuring elements, x is image index and k is the kernel size. The image indices run from 1 to N, where N is the image size.
f ( x ) x = 1, k + 1, 2 k + 1 g ( x ) = min[ g ( x 1), f ( x )] x = 2,....k ; k + 2,....2k ; 2 k + 2......, 3k ;.......

move of g(x) and k/2 units rightward horizontal move of h(x) are needed., and + is used to fill the parts moved out. Apparently, such calculation may increase the time cost of erosion (dilation). On the other hand, we have noticed that the horizontal move mentioned above are not necessary for the reason that min (+, g(x)) =g(x) or min (+, h(x)) =h(x). If we stagger the comparison position of the two rows of pixels, then Formula (5) can be generated from Formula (4). With Formula (5) we can avoid the time spending on adding + to the end of rows (columns), thus erosion efficiency will be improved.
g ( x + k / 2) x [0, ( k 1) / 2) min( g ( x + k / 2), h( x ( k 1) / 2)) result ( x ) = x [( k 1) / 2, width 1 k / 2] h( x ( k 1) / 2) x [ width k / 2, width 1]

(1)
f ( x ) x = N , N k 1, N 2 k 1,... h ( x ) = min[ h ( x + 1), f ( x )] x = N 1,....N k ; N k 2,.... N 2 k 1;
result (x) = min[g(x+(k-1)/2) , h(x-(k-1)/2)] x=1&N

(2)

(3) From the three formulas above [7], we can easily know that by taking k/2 units leftward horizontal move of g(x) and k/2 units rightward horizontal move of h(x), the combination of these two operations constitute all the pixel values of an eroded image.

## 3. New Improved Algorithm

We take erosion as an example in this paper, for dilation, we just use min instead of max. The following notions are used: width is the image length of each row, k is length of the structure element, length is length of the auxiliary space, N is the ratio of width to k, defined in the new improved algorithm, n is multiple of the assistant space, M is segments separating each row (column) of the image, g(x) is the pixel value of the xth index in buffer g, h(x) is the pixel value of the xth index in buffer h, gi(x) and hi(x) are the ith segment of g(x) and h(x) selected from f(x), index is suffix index of the results buffer. To solve the first deficiency of Van Herk algorithm, we change Formula (3) to Formula (4): result ( x) = min[ g[ x + k / 2] , h[ x - (k -1) / 2]] (4) Thus structure elements of any length are available for operation. For erosion operation, if one rows (or columns) length of the image is not integral multiple to that of structure element, + should be added to the end of every row (column) of the image in order to make it so. When calculating eroded value for each row (column) with van Herk algorithm, k/2 units leftward horizontal

(5) Now we assume that the rows length of one image is integral multiple to that of structure element, which means Width=N k. Then the calculation uses van Herk algorithm required two extra auxiliary spaces whose lengths equals their widths. If the images size is relatively large, such as 1024*1024, then 2k extra space is required, which cost considerable space. In van Herk algorithm, each row of the image will be divided into N segments, and N extra spaces of structure elements length are synchronically allocated. But only in case that g(x) needs to be compared with h(x) will those spaces for comparison be necessary, which means other spaces can be save temporarily. Conducted by this method, we just need to insert those parts of pixels which need to be compared with into g(x) and h(x). When comparison of this part is done, the next pixel part will be operated in the exactly same way. Therefore, we can obtain the final expected eroded image when comparisons of all pixels are finished. In this way the purpose of saving space cost will be completed. Assumes length=k n n=1, 2, , N. When n=N, the space cost of new algorithm is just the same as that of van Herk algorithm. Now we divide each row into M parts, then the length of new allocated extra auxiliary spaces will be length .Every time we get n segment pixels of k length from f(x) and put them into g(x), h(x):

## Width / length Width%length = 0 M = Width / length + 1 Width%length 0

(6) Steps of the new algorithm: First, assign 0 to the initial value of index. Every time after assigning value to result (index), index automatically adds 1 itself. At the beginning, we get

186

values of g1(x) and h1(x) and let result (index) = g1(x+ k/2); x [0, (k-1)/2. Because part of value of g1(x) has been assigned to result (index), the pixels comparing position in two extra auxiliary spaces will be staggered for a certain distance. Now we have Formula (7):

## 4. Simulation Test and Analysis

The simulation test was implemented on PC computer. The software environment was Windows XP operating system and IDE programming software. The hardware environment was Pentium4 3.00GHz for CPU and 1.00GB RAM. Each data in the diagram below are average value via ten times of evaluating:
450 400 350 300 250 200 150 100 50 0 5*5 10*10 25*25 40*40
Van-Herk N=Width/K IA N=1 IA N=5 IA Normal

result (index ) = min[ g 1( x + ( k -1) / 2) , h1( x )] x [0, length - k ] (7) After all pixels of g1(x) have been compared, g2(x) is followed to be compared. However, comparison of h1(x) hasnt finished, so h2(x) is not permitted to be compared at this moment. Thus the pixels comparing position in two extra auxiliary spaces remain being staggered for a certain distance. Naturally, we will have Formula (8):

## result (index) = min[ g 2( x) , h1( x + length - k + 1)] x [0, k - 2]

(8) Similarly, after all pixels of h1(x) have been compared, h2(x) is followed to be compared while g2(x) has not yet finished its comparison . Comparison in such an interleaving way will continue till the last gMxand hM(x) are being compared in Formula (8). The new algorithm hasn t stopped after the interleaving comparison, for we have to assign value to result (index) finally as Formula (9):
result ( index ) = hM ( x + ( length - k + 1) / 2) x [0, k / 2 - 1]

Process time(ms)

## (9) To sum up, whole of the new algorithm are below:

g1( x + k / 2) x [0, (k 1) / 2) min( g i ( x + k 1), hi ( x)) x [0, length k ] i [1, M ] result (index) = min( g i +1 ( x), hi ( x + length k + 1)) x [0, k 2] i [1, M 1] hM ( x + length k + 1) x [0, k / 2 1]

(10) In Formula (10), the value of length should be calculated again when these two steps min [gM(x+k-1), hi(x)], x [0length-k] and hM(x+length-k+1) x [0, k/2-1] are on operation in condition that width% length0. Thats to say, length=width% length. Using this new method we need neither horizontal move of g(x) and h(x) nor extra spaces as the same row (line)s length of image. Consequently, erosion

Normal algorithm, as its structure elements size is m*n, will disassemble the structure element to m*1 and 1*n and then erosion (dilation) with them separately. In this way the times of comparison of each pixel is only m+n. Also it doesnt need any image expansion or extra auxiliary spaces because it doesnt require the image to have the length of row (column) being integral multiple to that of structure element. So it cost no extra space, which means it may be the best algorithm in case the structure element is relatively small. Nonetheless, the running time of normal algorithm varies according to the size of structure element. It doesnt suit for the operation with large structure element for its running time will increase as well as the structure elements length. For improved algorithm with condition N=Width/K, its space cost renders the same as van Herk algorithm. But from the chart above we can see it has less running time, for it doesnt require any horizontal move of g(x) or h(x). For improved algorithms with condition N=1 and N=5, their running time are related to the size of their structure elements. In details, the running time decreases in a small range as the length of structure element increases. According to the introduction of the new algorithm above, the times g(x) and h(x) being called are Width/Length, so when Length gets bigger, the called times decreases. Consequently the time

187

spend on functions calling becomes less. Besides, we can find out an interesting phenomenon from the chart that when it has long structure element, no matter in condition N=1 or N=5, its running time is very close to that of the condition N=Width/K. Therefore, we suggest set N=1~5 in practical use whiles the value N=Width/K is totally unnecessary.

5. Conclusions
This paper introduces a new fast algorithm based on van Herk algorithm for erosion (dilation), and successfully proved its validity and availability by establishing emulator program. The new method can reduce both the time spend on erosion (dilation) process and the required extra auxiliary spaces. As a result the efficiency of erosion (dilation) has been improved. Using the new algorithm to deal with large structure elements can reach its best performance.

6. Acknowledgment
This work is supported by Foshan Special Fund Project of Production, Academy and Research (grant No.2007B1038).

7. References

[1] C.L. Luengo Hendriks, and L.J. van Vliet, Discrete Morphology with Line Structuring Elements, Computer Analysis of Images and Patterns, Springer, Berlin, Volume 2756, 2003, pp. 722-729. [2] P. Soille, and H. Talbot, Directional morphological filtering, IEEE Transactions on Pattern Analysis and Machine Intelligence, Volume 23, No.11, Nov.2001, pp. 1313-1329. [3] A.Katartzis V.Pizurica, and H.Sahli, Applications of mathematical morphology and Markov random field theory to the automatic extraction of linear features in airborne images, Mathematical Morphology and its Applications to Image and Signal Processing, Springer US, Volume 18, 2000, pp.405-414. [4] C.L. Luengo Hendriks and L.J. van Vliet, A rotationinvariant morphology for shape analysis of anisotropic objects and structures, Visual Form 2001, Springer, Berlin, Volume 2059, 2001, pp.378-387. [5] Chris Houser, Cheryl Hapke, and Stuart Hamilton, Controls on coastal dune morphology, shoreline erosion and barrier island response to extreme storms, Geomorphology, Volume 100, August 2008, pp.223-240 . [6] P. Soille, and H. Talbot, Image structure orientation using mathematical morphology, 14th International Conference on Pattern Recognition (ICPR'98), Volume 2, 1998 , pp.1467-1469. [7] Van Herk, M. , A fast algorithm for local minimum and maximum filters on rectangular and octagonal kernels, Pattern Recognition Letters Volume 13 , July 1992, pp.517521.

188