Fast Streaming Algorithm for 1-D Morphological Opening and Closing ...

44 downloads 0 Views 528KB Size Report
Abstract. This paper presents a new streaming algorithm for 1-D morphological opening and closing transformations on 2-D support. Thanks to a recursive com-.
Fast Streaming Algorithm for 1-D Morphological Opening and Closing on 2-D Support Jan Bartovsky1,2,3 , Petr Dokladal1 , and Eva Dokladalova2 1

2

3

Center of Mathematical Morphology (CMM), Mines ParisTech, 77305 Fontainebleau Cedex, France [email protected] Laboratoire d’Informatique Gaspard Monge, Equipe A3SI, ESIEE Paris, University Paris-Est, 93162 Noisy le Grand Cedex, France {bartovsj,dokladae}@esiee.fr Faculty of Electrical Engineering, University of West Bohemia, 30614 Pilsen, Czech Republic

Abstract. This paper presents a new streaming algorithm for 1-D morphological opening and closing transformations on 2-D support. Thanks to a recursive computation technique, the algorithm processes an image in constant time irrespective of the Structuring Element (SE) size, with a minimal latency and very low memory requirements, supporting various input data types. It reads and writes data strictly sequentially in the same (horizontal) scan order for both the horizontal and vertical SE. Aforementioned properties shall allow an efficient implementation in embedded HW that opens a new opportunity of a parallel computation. Besides that, this algorithm is also very competitive in the C implementation.

1

Introduction

Within several last decades, the Mathematical Morphology (MM) [1] has not only evolved into a distinguished theory, but it has also settled in useful and practical applications in a general image analysis, industry control etc. One branch of these application is based on local feature detection, such as local texture orientation or granulometry [2]. The granulometry is a basic texture or random media analysis tool [3]. Traditionally, it stems from iterative sieving of image elements through successively coarser sieves obtaining a size distribution. A different approach was introduced by [4] who proposed a dedicated algorithm to compute the size distribution directly. Obviously, these results can be used as statistical descriptors in many modern application based on machine learning techniques. The recent development of computer algorithms focuses on decreasing the number of comparisons per pixel, which are evaluated sequentially, and therefore, have a large impact on its performance, consuming a large amount of working memory. On the other hand, dedicated HW systems have usually unlike limitations. The number of comparisons is not necessarily of such high importance because they can be evaluated in a parallel way in, e.g., FPGA or CPLD devices. These systems are often memory-limited in terms of the size and bandwidth. In order to comply to this restriction, we assume the strictly sequential input and output data access as compulsory.

The paper is organized as follows: Section 2 outlines a brief overview of related morphological algorithms. Section 3 remarks the basic notion of morphological transformations. Section 4 describes the main principle of the algorithm called Recursive Peak Elimination. Section 5 presents the functional C implementation and a pseudocode of the algorithm. Finally, Section 6 presents performance results of computer benchmarks and a comparison with other algorithms. 1.1 Novelty We propose a new algorithm for morphological opening and closing with the following properties. The algorithm processes an image strictly sequentially in horizontal scan order with the minimal computation latency, which is inferred by the SE. The execution time is globally constant, independent of SE properties (size, orientation) and data precision (from 8-bit integer to 64-bit double float), the worst-case of which is upper bounded. Along with the very low memory requirements, which are much lower than the mere size of the image to process, these features make the algorithm especially interesting for time-critical and memory-limited HW systems. Moreover, the sequential C implementation of this algorithm can also compete with other common morphological algorithms.

2

State of the Art

In this section, we present a basic overview of existing 1-D algorithms for morphological dilation/erosion that are used in computing openings and closings, see Section 3, below. The first fast and still the most popular dilation algorithm is van Herk [5]. Although the computation complexity is independent of SE, it requires two passes: causal and anticausal, which make any stream processing difficult. Later, Gil and Kimmel [6] improved van Herk algorithm and reduced the number of comparison to only 1.5 per pixel. However, the computing latency depends on the SE size and the memory requirements are increased. In [7], Lemire proposed a fast, stream-processing algorithm for causal linear SE. It runs also on floating-point data, has low memory requirements and zero latency. However, an intermediate storage of local maxima results in a random access to the input data. This problem is solved in Dokladal [8] who proposed a new algorithm with very low memory requirements and zero latency. A different approach represents the direct opening computation published by Van Droogenbroeck and Buckley [9]. They proposed an anchor based algorithm, where anchors are these points of the input image that remain unaffected by corresponding operation. This algorithm has very large memory requirements as it buffers entire input and output image. A histogram is used for calculation that makes it dependent on the number of gray levels.

3

Basic Notions

Let δB , εB : Z2 → R be a dilation and an erosion on grey-scale images, parameterized by a structuring element B, assumed flat (i.e., B⊂Z2 ) and translation-invariant, defined

as δB (f ) =



fb ;

εB (f ) =



fb

(1)

b b∈B

b∈B

The hat b denotes the transposition of the structuring element, equal to the set reflection b = {x | −x ∈ B}, and fb denotes the translation of the function f by some scalar b. B The SE B is equipped with an origin x ∈ B. Let φB , γB : Z2 → R be a closing and an opening on grey-scale images, parameterized by a structuring element B, assumed flat (i.e., B⊂Z2 ) and translation-invariant, defined as (2) φB (f ) = εBb [δB (f )] ; γB (f ) = δBb [εB (f )] The closing and opening are dual transformations. Hereafter, our explanation is focused on the opening with no deliberate reason. Notice that the same principles can be applied to the closing in accordance to the duality property.

4

Principle of Algorithm

We describe the main principles of our algorithm in this section. In the beginning, we observe the influence of the opening transformation to a 1-D signal so that we can easily clarify the algorithm behavior afterwards. At first, let us observe a behavior of the opening transformation (2) to a simple 1-D signal in Fig. 1. The opening literally cut off the peaks narrower than SE (the closing on the other hand fills the valleys narrower than SE). Remark here that γB is invariant to the translation of the SE B so γB is not affected by the origin of B. The proposed algorithm executes the peak cutting recursively, from the top downwards. Contrarily to the traditional composition (2), it handles image borders correctly so the peak of the whole size of SE is eliminated, see Fig. 1.

SE

f(t)

f(t)

f(t)

SE

t

γB=δB(εB)

t

t Alg.1

(a)

(b)

(c)

Fig. 1. Effects of opening and closing transformations on a 1-D signal: (a) opening cuts the peaks off; (b) closing fills the valleys; (c) edge opening of our algorithm compared to the conventional solution (2).

4.1 Recursive Peak Elimination The Recursive peak elimination (RPE) is a part of the algorithm that manages the successive removal of signal peaks. It is composed of two tasks. At first, the input signal

is continuously scanned in order to identify peaks. When a peak is encountered, the second task of peak elimination is invoked. Remark that a point of an input signal f (x) is a peak if both its very precedent and subsequent points are smaller, such as f (x) > f (x − 1) ∧ f (x) > f (x + 1).

(3)

The algorithm recognizes 4 basic configurations, see Fig. 2, each of them affects the algorithm behavior in a different way. Notice that van Droogenbroeck [9] opening algorithm has 6 configurations. All configurations can be divided into 2 groups; those that characterize a peak ((a) and (b)), and those that do not ((c) and (d)).

f(t)

f(t)

f(t)

x-1

x x+1 t (a)

x-1

x x+1 t (b)

f(t)

x-1

x x+1 t (c)

x-1

x x+1 t (d)

Fig. 2. Four different pixel configuration for peak identification. Conf. (a) and (b) characterize a peak, conf. (c) and (d) do not.

The peak identification process proceeds as follows. At first, f (x) is compared with its precedent value f (x − 1). If f (x) < f (x − 1) (configuration (d)), the f (x) value is not a peak. If not, the following value f (x + 1) is taken into comparison in the next step. Then if f (x + 1) < f (x − 1) the f (x) value conforms to peak configuration (a); else if f (x + 1) < f (x) ∧ f (x + 1) > f (x − 1), the peak configuration (b) is encountered. Otherwise (f (x + 1) > f (x)), the point f (x) is classified as configuration (c), monotonously increasing function. When a signal peak is identified, it is supposed to be removed by the peak elimination task. Obviously, the value of a signal peak is unnecessary, and therefore, it can be immediately retrieved out of the computation. The retrieved peak value is then replaced by one of the two neighboring values in dependence on the peak configuration. The f (x) is replaced by f (x − 1) in configuration (a), or by f (x + 1) in configuration (b), respectively. The flowchart of the whole RPE procedure is depicted in Fig. 3 a. The first step is always the identification of a peak. In the case a peak is recognized, the elimination task removes it. After the peak removal, the whole process will be repeated if, and only if, the peak is of configuration (a). The reason is that a peak may span over more than one pixel, and therefore, previous pixels must be tested on peak conditions as long as configuration (a) is recognized. Because the maximal length of the peak to eliminate is equal card(B) − 1, the RPE iterates over previous card(B) pixels only. The aforementioned method needs the input data to contain a zero value duplicity. It means that two following data samples must not have the same value (it would disallow the peak identification). Hence, the data are efficiently coded into pairs of {value, last position of plateau} as it is depicted in Fig. 3 b. Notice that if a plateau is a peak, it will

Start Identify peak

Is peak?

f(t)

+

-

{4,3}

4

Eliminate peak

{2,2}

2

End

{4,11} {3,7}

3

-

Conf. (c)?

(a) Flowchart

+

{1,9}

1 0

0

1

2

3

4

5

6

7

8

9

10 11

t

(b) Data coding

Fig. 3. (a) Flowchart of Recursive Peak Elimination. (b) Illustration of efficient data coding. Each data plateau is represented by a single pair of {value, last position of plateau}

be removed in a single operation. The position also defines whether a pixel belongs to the SE that moves over data.

5

Implementation

In this section we describe the C implementation of the proposed algorithm capable of operating with horizontally- and vertically-oriented 1-D SE. In both cases, the input and output data access is strictly sequential in the horizontal scan order (each line is read from the left to the right, line by line). For the sake of simplicity, let us consider the horizontal SE first. The implementation uses the double-end FIFO (First In First Out) structure called queue that serves as an elementary memory block to store the previously received values. It allows us to read and delete values from both ends of an ordinary FIFO. The algorithm is composed of 2 parts. The first is an executive part that contains all the necessary commands to process one input data sample and output one result data sample according to the before mentioned principles. It manages the data-flow, borders handling, and the whole computation itself. See Alg. 1 for a pseudocode listing. The second one is an iterative, double for-loop part that is intended to call Alg. 1 for each point of the input image the listing of which is obvious, and therefore, omitted. For correct handling of borders, the input image area is extended by padding of the SE size in the direction of the SE orientation. For example, considering SVGA image 800 × 600 px, horizontal SE 25 px, the image area for Alg. 1 is 825×600. The single call of Alg. 1 proceeds as follows. At first, the large while-loop executes the RPE with zero value duplicity. As it was described at section 4.1, it comprises of the peak identification using 4 configurations and the peak elimination. The while condition F ≤ Q.back()[1] terminates the RPE when a non-peak configuration (c) (or possibly (d)) is encountered. The condition on line 2 retrieves the last stored value from the queue if it is equal to the current sample to prevent the value duplicity. The following condition on line 5 evaluates two previously stored pixels to exclude configuration (d).

Algorithm 1: Y ← 1D

OPEN

(F, rp, SE, Q)

Input: F - input signal sample f (rp); rp - actual reading position; SE - SE size; Q pointer to actual Queue Result: Y - sample of opening γ[f (t)](rp − SE) Data: Q - a Double-End Queue Q.back()[] - accesses the last enqueued pair {F, rp} Q.back(2)[] - accesses the last but one enqueued pair {F, rp} 1 2 3 4 5 6 7 8

while F ≤ Q.back()[1] do if F = Q.back()[1] then Q.dequeue() ; // Dequeue constant value, prevent duplicity // Exit while loop break ; else if Q.back(2)[1] SE size

71

91

Fig. 7. Execution time of opening versus the size of the horizontal structuring element. Natural photo 800 × 600 px is used.

References 1. Serra, J.: Image Analysis and Mathematical Morphology. Academic Press, Inc., Orlando, FL, USA (1983) 2. Menotti-Gomes, D., Najman, L., de Albuquerque Ara´ujo, A.: 1D Component tree in linear time and space and its application to gray-level image multithresholding. In: Proceedings of 8th ISMM. Volume 1., INPE (2007) 437–448 3. Matheron, G.: Random sets and integral geometry [by] G. Matheron. Wiley New York, (1974) 4. Vincent, J.: Granulometries and opening trees. Fundam. Inform. 41(1-2) (2000) 57–90 5. van Herk, M.: A fast algorithm for local minimum and maximum filters on rectangular and octagonal kernels. Pattern Recogn. Lett. 13(7) (1992) 517–521 6. Gil, J., Kimmel, R.: Efficient dilation, erosion, opening, and closing algorithms. IEEE Trans. PAMI 24(12) (2002) 1606–1617 7. Lemire, D.: Streaming maximum-minimum filter using no more than three comparisons per element. CoRR abs/cs/0610046 (2006) 8. Dokladal, P., Dokladalova, E.: A zero-latency, optimal-memory algorithm for morphological operations. Technical Report N-01/10/MM, Mines-ParisTech, France, CMM (Jan. 2010) 9. Van Droogenbroeck, M., Buckley, M.J.: Morphological erosions and openings: Fast algorithms based on anchors. J. Math. Imaging Vis. 22(2-3) (2005) 121–142

Suggest Documents