A Fast Algorithm for Morphological Erosion and Dilation
Total Page:16
File Type:pdf, Size:1020Kb
A FAST ALGORITHM FOR MORPHOLOGICAL EROSION AND DILATION C. Jeremy Pye J. A. Bangham School of Information Systems, University of East Anglia, Norwich, NR4 7TJ, UK. Tel: +44 0 1603 456161; Fax: +44 0 1603 453345 Email:[email protected],[email protected] ABSTRACT maximum and minimum values as the histogram adapts it k l This paper describes a new algorithm for performing erosion is possible to reduce the computation required by a l and dilation which is suitable for flat line-segment structur- structuring function from kl down to computations per el- ing functions, and which has a computational complexity ement. A drawback of this type of method is that the data that is independent of the structuring function size. Unlike must be represented by a fixed number of bits in order to a other proposed algorithms, the computation time required by build a histogram. Astola [4] presents a similar method based this method is directly proportional to the number of extrema upon a double heap structure which elevates this constraint. within the signal being processed. This makes it particularly Recently several algorithms designed to perform the fast cal- suitable for signals and images that have large and slowly culation of the running maximum or minimum on a one varying segments. dimensional signal have been presented. Pitas [5, 6] de- velops an algorithm based upon the ”divide and conquer” 1 INTRODUCTION principle designed to exploit the redundancy in the running calculations, resulting in a reduced number of comparisons Since its evolution in the late 1970's, mathematical morphol- k per element log . Herk [7] proposes an alternative algo- ogy [1] has been regarded as a powerful discipline suited rithm based upon a restricted distance transform. Using this to image processing and analysis. Underlying mathemati- method the number of comparisons per element is reduced to cal morphology are two primitive operations, known as ero- just and is independent of the window size. sion and dilation. All morphological operations can be con- Whilst these methods demonstrate significant improvement structed from a combination of erosions and dilations. A tra- k over the general O solution under certain circumstances ditional and naive implementation of these two operations is these algorithms are rather inefficient. based upon the technique employed for order-statistic filter- ing, which involves passing a window, or structuring func- 2 FAST RUNNING MAXIMUM tion, over the signal and at each position recording the ith x ranked value within the window. Erosion and dilation re- Consider a discrete input signal consisting of elements i i Z quire finding either the maximum or minimum value within R . In this paper we will only consider the running the window. This is a special case of order-statistic filter- maximum as the running minimum can be obtained by sim- ing because it does not require a sorting of the windowed ply inverting the signal before and after processing. In order values. Instead, selection of either the maximum or mini- to simplify the explanation of the algorithm the structuring mum requires only a single pass through the windowed val- element will consist only of delayed input elements, that is k k ues. This has a computational complexity of O where y max x x x i i k ik is the number of samples contained within the window or i (1) structuring function. Through the wise use of structuring el- ement decomposition [2] it is often possible to reduce the although the more usual running maximum [5, 7] can be ob- n number of computations required by splitting the structur- tained by simply shifting the output signal by ing element into a number of smaller structuring functions. elements. k l For example, if an image is dilated using a flat size In order to understand the inefficiencies of the present algo- structuring function, the same result can be achieved using rithms it is necessary to examine a number of input scenarios. k l two separate structuring elements of size and . This clearly reduces the number of computations per element 2.1 Monotonic k l from kl down to . Other methods [3] involve maintain- Given a monotonic signal as input, that is a signal whose ing local histograms of the values within the window. As elements are all of a constant value, the window moves from one position to the next many of x x max x x x i i i i the samples within the window remain. By monitoring the i (2) and hence, 2.5 Local minimum A local minimum occurs when two local maxima exist within y max x x x i i ik ik x (3) the same signal. It is formed at j when a positive ramp x i follows a negative ramp, that is 2.2 Positive ramp x i j i x Given a signal in which the elements are ordered so that they i (12) x ij form a positive ramp, i The output due to the negative ramp component of the signal, x x max x x x i i i i i (4) is formulated in subsection (2.3), and hence, y x i j i k i (13) y max x x x i i ik ik (5) Similarly, from subsection (2.2), the component of the sig- x i nal that forms a positive ramp is unaffected by the filtering 2.3 Negative ramp process. That is, Given a signal in which the elements are ordered so that they y x i j k i i (14) form a negative ramp, ijn The output between the limits j cannot x x max x x x i i i i i (6) be determined so easily as none of the previous cases apply. and hence, From equation (1) the output between these limits is given by, y max x x x i i ik ik (7) y max x x x i i k ik i (15) x ik 2.4 Local maximum This can be decomposed into two parts. Given that the signal Consider now a signal that has a positive ramp followed by a for all ij forms a positive ramp the maximum of the sam- i j x ples between and is i . Also, because the signal for all negative ramp, forming a single maximum at position j . That j is, i forms a negative ramp, the maximum of the samples i j x k between and is i . Therefore, x i j i x y max x x jijk i (8) i i ik x ij i (16) From subsection (2.2) the component of the signal that forms In conclusion given a local minimum the output is given as, j the positive ramp is unaffected by the filtering process, i . Also, from subsection (2.3) the component of the signal that x i j ik jk forms a negative ramp is also unaffected, i . y max x x jijk i i ik However, part of the signal does not fit into either of these (17) x i j k i i j cases. From equation (1), between the limits j k the output of the filter is given by 2.6 Combinations local maxima and minima y max x x x i i Whilst the cases so far discussed are valid they are in gen- k ik i (9) eral unlikely to occur individually. It is much more likely When the window is positioned at the extreme left of this that a number of local maxima and minima will exist within j limit so that i , then the same signal. If local maxima occur in close proximity to each other then the simplifications obtained by separating y max x x x i j k j k j (10) the signal into various component parts, as demonstrated in subsection (2.5), do not apply. x clearly the window contains j which by definition is known to be the maximum value within the signal. Similarly, when Figure (1) shows a signal containing three local maxima at abc ba k cb the window is positioned at the extreme right of these limits, positions a b c. Where and k x x a and the ordering of the maximum are b j k that is i , it is clear that the window also contains x c . Each local maxima is separated by a corresponding local x x j k the element i . In conclusion, a d b e minima at the positions d e f , where cf. It is clear from this diagram that the output due to the x i j i x x x a c maximum b is affected by both and . y x ji j k i j (11) In order to calculate the output given this interference caused x ij k k i by proximity, it is necessary to re-formulate the output with x x r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r x x x x x x x x x x x x f f a d a d c c b e b e y A y r r r r r r r r r r r r r r r r r r r r r b b b b y y y y a b c a Figure 1: (Top) Shows a signal x which contains three local x x x b c maxima a , and .