You are on page 1of 9

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/230838044

Image segmentation by advanced morphological filtering and clustering

Conference Paper · January 1997

CITATIONS READS

4 155

3 authors, including:

Marcin Iwanowski Slawomir Skoneczny


Warsaw University of Technology Warsaw University of Technology
86 PUBLICATIONS   613 CITATIONS    32 PUBLICATIONS   39 CITATIONS   

SEE PROFILE SEE PROFILE

All content following this page was uploaded by Marcin Iwanowski on 20 May 2014.

The user has requested enhancement of the downloaded file.


IMAGE SEGMENTATION BY ADVANCED MORPHOLOGICAL FILTERING AND
CLUSTERING

Marcin IWANOWSKI, Sławomir SKONECZNY, Jarosław SZOSTAKOWSKI

Warsaw University of Technology, ul.Koszykowa 75, 00-662 Warszawa, POLAND

ABSTRACT

This paper is devoted to a segmentation method consisting of two steps: advanced


morphological filtering by reconstruction and clustering by k-means algorithm. First step is
based on morphological reconstruction and two filters are applied: opening by reconstruction
and closing by reconstruction. This kind of operation has very important advantage from the
point of view of segmentation - it preserves the borders of regions. Traditional filters
(opening, closing, linear filters) remove noise, but on the other hand they cause some blur
effects, which can be the serious obstacle for correct segmentaion. Morphological filtering by
reconstruction has very good filtration properties without changing the shapes.
Second step of segmentation consists of clustering. Two versions of k-means clustering
algorithm will be described: classic and fuzzy one. First, 'crisp' version will be applied to the
cases with a knowledge regarding number of clusters given a priori. Fuzzy version should be
used when it it is difficult to define cluster number. The algorithm will automatically adapt
number of clusters into the structure of the image. A combination of filtering by
morphological reconstruction and clustering makes possible to consider two kind of
information: spatial (filtering) and spectral (clustering).

Key words: clustering, fuzzy logic, k-means, mathematical morphology, reconstruction

INTRODUCTION

The presented method is divided into two steps: morphological filtering nad clustering. First
step is the preprocessing step performed in order to consider spatial dependencies in the
image. The main areas of the image are transformed to more homogeneous. It means that all
of the pixels with the graytone considerably lighter or darker than their background are
removed in order to avoid misclassifications during the second, clustering step. Typical
solution for such kind of problem is opening, closing, or linear filtering. But they change the
shapes of regions on the image (bluring), which is the main obstacle for using this kind of
filters in segmentation process. Segmentation should extract the shapes in the image, so each
distortion of shape is dangerous. In order to solve this problem more advanced mathematical
morphology is used: geodesic operators. Based on this operators two filters can be defined:
opening by reconstruction and closing by reconstruction. They both remove lighter or darker
pixels or areas on the image's surface, but they do not change the shapes. So they are very
well suited for the segmentation purposes.
The second step of proposed method is called clustering and is destined to a clasification of
image's pixels. To do this the k-means algorithm is used. This algorithm is iterative and
consists of two steps: clasification and calculation of cluster centers. Each iteration gives
better approximation of the cluster centers. The algorithm is itertively performed while the
cluster centers are moving. Each pixel is classified to the cluster with the closest center.
Clusters are represented by theirs centers, and they correspond with the regions on the image.
Two kinds of a k-means algorithms are considered. The first one is traditional and gives as the
result the number of clusters which is given by the user. The second is based on fuzzy logic. It
can give as the result the number of clusters different from those given at the beginning of the
algorithm. In this case the number of clusters is adapted to the real structure of the image. The
algorithm starts with given number of clusters and later this number can increase or decrease
depending on the spectral distribution of image's pixels.

MORPHOLOGICAL FILTERING BY RECONSTRUCTION

Mathematical morphology is a very efficient non-linear tool for signal and image processing.
An introduction to mathematical morphology is to find in (Serra, 1982; Serra, 1988). In this
paper morphological filtering by reconstruction is considered. The following part describes
briefly theoretical background for opening and closing by reconstruction. Both operations
belong to one group called geodesic morphological transformations (Soille, 1994).
Geodesic dilation (erosion) of size 1 of the marker image f with respect to the mask image g
where f ≤ g ( f ≥ g ) is defined as infinimum (supremum) image of mask image and marker
image after dilation (erosion) of size one - with elementary structuring element, and is
denoted as: δ g(1) ( f ) ( ε g(1) ( f ) ):
δ g(1) ( f ) = δ (1) ( f ) ∧ g , ε g(1) ( f ) = ε (1) ( f ) ∨ g, (1)

Geodesic dilation (erosion) of size n consists of n succesive geodesic dilations (erosions) of


size 1:
δ g (n) ( f ) = δ g (1) ( δ g(1) .... δ g (1) ( f )...)) , ε (gn) ( f ) = ε (g1) ( ε (g1) .... ε (g1) ( f )...)) (2)
n − times n − times

Reconstruction by dilation (reconstruction by erosion) of a mask image f from a marker image


g where f ≤ g ( f ≥ g ) is defined as succesive geodesic dilations (erosions) of f with respect
to g performed until idempotence and is denoted by: Rg ( f ) ( Rg∗ ( f ) ):

Rg ( f ) = δ (gi ) ( f ) , Rg∗ ( f ) = ε (gi ) ( f ) , (3)

where i such that (idempotence): δ (gi ) ( f ) = δ (gi +1) ( f ) , ε (gi ) ( f ) = ε (gi +1) ( f ).
More information about reconstruction is in (Soille, 1994; Vincent, 1992).
Opening and closing by reconstruction are defined as follows:

γ (Rn) ( f ) = Rg ( ε (n) ( f )), ϕ (Rn) ( f ) = Rg* (δ ( n) ( f )). (4)

Unlike traditional opening and closing, opening by reconstruction and closing by


reconstruction preserves shapes in the image. It is very important while using these operations
as a first step of segmentation. It makes possible removal of the local peaks of gray-intensity
without changing the borders of regions (which happens in traditional opening and closing).
One of the most efficient filters are alternating sequencial filters (ASF), which are consist of
two families of filters. Each family contains operation of the same type but of different,
increasing size. It can be defined as follows:

ASF i = α (i )β (i ) ... α ( 2)β ( 2) α (1)β (1) (5)

α, β are the families of filters, i is defined as a size of filter. In most of cases


α and β represent opening and closing (Meyer and Serra, 1989; Serra and Vincent, 1992). In
our case we use these operation by reconstruction where α means closing by reconstruction
and β - opening by reconstruction. We will call this filter later ASF by reconstruction
(ASFR):

ASFR i = ϕ R ( ) γ R ( ) ... ϕ R ( 2) γ R ( 2) ϕ R (1) γ R (1)


i i
(6)

CLUSTERING

Up to now a huge amount of segmentation algorithms was developed. In general one can
divide them into two groups (Soille, 1992): based on spectral and spatial properties of the
image. To the first group belong all the algorithms based on the intensity of image's pixels
like e.g. clustering. Second group bases on the relationships between pixels and theirs
neighbors. To this group belongs the most popular morphological segmentation technique -
watershed (Beucher, 1990; Meyer and Beucher, 1990). This paper describes only first type of
segmentation - clustering. In our case not only spectral properties are considered because first
step - morphological filtering was performed. Those step have removed the undesirable
intensity peaks using the spatial information, so the spatial constraints are in such a manner
considered.
Proposed clustering method bases on the k-means technique (Duda and Hart, 1973; Selim and
Ismail 1984; Śluzek, 1991; Iwanowski, 1996). K-means algorithm aims at classifying each
member of given set of input data into given number of clusters. Algorithm deals with
distances between samples and cluster centers. This distance is iteratively minimized in two
steps performed iteratively. First step distributes samples into the clusters, second updates
cluster centers. Each sample is classified to the cluster which center is the nearest in given
metric. Updating of cluster centers is performed by computing a new cluster center by placing
it in the middle (arithmetic mean value) of all of the samples belonging to the cluster. These
two steps are performed iteratively while clusters centers change their position. If in the last
performed iteration cluster centers did not move, it means that operation of samples
classification is finished. In case of applying k-means algorithm for images notions of sample
and cluster center are represented by pixel's graytone. During the calculations the distance
between samples and cluster centers is calculated by taking absolute value of difference
between graytones of sample and cluster center. Cluster centers obtained finally represents
graytones of the output image. These graytones refers to regions on the image surface.

Whole algorithm can be written as follows:

1. Set initial cluster centers (output graytones).


2. Classify pixels. Each pixel is labeled by the id number of the closest cluster.
3. Calculate new cluster centers (output graytones).
4. If in cluster centers obtained in step 3 are different to centers obtained in previous
iteration then go to step 2, otherwise go to step 5.
5. Using cluster centers (output graytones) classify pixels of the input image into output
one. Change value of each pixel to the value of the closest cluster center.

Initial cluster centers (point 2 above) can be calculated in any way. We have placed them
equally distanced in a whole range of graytones.
Next remark refers to the spectral property of this kind of segmentation. Because k-means
does not consider neither position of pixel nor its neighbors, there is no need to make all of
the calculations on image. Image histrogram is sufficient to do this. This solution is faster
because it needs smaller amout of computations.
In version of the algorithm described above number of clusters is fixed and cannot be
changed. This solution is not always sufficient. Sometimes one would have flexible algorithm
which can change the number of cluster according to the real situation on the image. In this
case fuzzy version of k-means algoriithm (fuzzy k-means - FKM) can be applied. Some fuzzy
versions of k-means was developed. In this paper version close to (Huntsberger et al., 1985) is
proposed. The main difference between traditional and FKM algorithm is representation of
the result. In traditional version each point is labelled by the cluster number. Fuzzy version
produces so called 'fuzzy partition' - a vector which includes membership values. These
values tell us 'how much' given point is similiar to each of the clusters. This is not only
indication of the closest cluster center but also a description of similiarity with other clusters.
The schema of algorithm is similar to that presented above. Only some changes should be
made. Calculation of cluster centers is performed using the following equation:


n
j =1
( µ ij ) m x j
ci = (7)

n
j =1
( µ ij ) m

(all symbols will be explained later)


Classification step computes new vector with membership values and is performed for each
pixel (index p) as follows:
- compute distance between pixel and cluster centers: ∀1 ≤ i ≤ k ; dip = x p − ci
- if one or more distances d are equal to zero perform for all 1≤i≤k:

µ ip = 0 if dip = 0
(8)
µ ip = 1l otherwise
(l - number of distances d equal to 0)
otherwise for all 1≤i≤k:
1
µ ip = k
(9)
∑(
dip 2 /( m −1)
d jp)
j =1

where: n - is the number of pixels, ci - is center of i-th cluster, x p - is i-th sample (pixel), µ ip -
is the element of fuzzy partition, it describes membership value: 'how much' p-th sample
belong to i-th cluster. Parameter m describes degree 'fuzziness' of classification (nature of
clustering). m=1 gives 'hard' or 'crisp' clustering, bigger m give fuzzier classification.
Presented above descriptions refers to 'pure' FKM algorithm. In order to apply it to
segmentation some additional steps should be made. FKM algorithm is performed until
convergence. When the fuzzy-partition elements stops changing their elements, next step is
executed. Cluster centers are compared in order to check if there are clusters with centers
close to each other. If two or more clusters have their centers close, they represent in fact one
cluster. In this case number of clusters k decreases and FKM algorithm is performed once
again. When number of clusters is stable next step is performed. Now all the pixels with the
membership values high enough are classified to the clusters with the highest membership
value. The thresholding operation with threshold which describes how 'high' is 'high enough'
is called α-cut. All the pixels not classified (their membership values were too small to be
classified properly) are classified once again using FKM.

Whole algorithm can be summarized as follows:

1. Set whole image as a set of pixels for classification.


2. Perform FKM:
2a. Initialize fuzzy partition.
2b. Generate fuzzy partition (membership values for each pixel).
2c. Calculate new cluster centers.
2d. If new cluster centers are different to previous ones go to step 2b.
3. Check if real number of clusters after FKM is equal to k
if yes then go to step 4, otherwise set k=real number of clusters and go to 2.
4. α-cut, classify all the pixels with membership values higher than α to the closest
clusters.
5. If not all pixels were classified in step 4 then set not-classified pixels as a new set for
classification and go to step 2, otherwise stop the algorithm.

RESULTS

In order to apply proposed algorithm some experiments were carried out. We used 256-
graytone images, resolution 256x256 pixels.

Fig. 1. (a) - input image (mangan), (b) - after ASF of size 2, (c) - after ASFR of size 2, (d) -
after ASFR of size 2 and k-means (k=2).

Fig. 1. shows the results of two kinds of filtering: by ASF and by ASFR. First one consists of
four operations: closing of size 1, opening of size 1, closing of size 2, opening of size 2 (ASF
of size 2). It is visible that all the disturbances on the background have disappeared, but at the
same time shapes of objects have been changed.
Fig. 2. (a) - intensity of pixels from Fig. 1a, (b) - after ASFR of size 1, (c) - after ASFR of
size 2, (d) - after ASFR of size 2 and k-means (k=2).

Second filter gives correct result. It is ASFR filter of size 2 contained closing by
reconstruction and opening by reconstruction (size 1 and 2). Image is filtered without any
change of shape of objects.
Image filtered by ASFR is much better input for k-means algorithm than image without
filtering. Only the important regions exists and theirs borders are unchanged. In this case
'crisp' version of k-means algorithm was applied. Number of clusters is known - we have to
extract darker shapes on lighter background - and is equal to 2. Result of k-means of size 2 is
presented in Fig. 1d.
Fig. 2. includes the 1-D views of the image from Fig. 1a made by horizontal cut of image at
y=120. At the first image (Fig. 2a) initial image is shown - image containes a lot of local
graytone disturbances which, from the point of view of 'pure' image analysis, represent noise.
This noise should be removed. K-means applied directly on this image gives bad result,
because apart from the proper areas also a lot of noise will be considered as objects.
Next picture (Fig. 2b) shows the result of filtration by ASFR of size 1. Some smaller peaks
disappear, but larger remain, so the size of ASFR should be increased. At the next picture
(Fig. 2c) result of ASFR of size 2 is presented. All the important peaks are removed so k-
means can be now applied. Result of this operation is shown on Fig. 2d.

Fig. 3. Other examples: (a) granite, (b) granite after ASFR of size 2 and k-means (k=3), (c)
cooper, (d) cooper after ASFR of size 1 and k-means (k=2).

Fig. 3. contains other examples of proposed segmentation method also with 'crisp' k-means.
Fig. 3a presents structure of granite. Three main areas exists on this image. This case needs
ASFR of size 2 and k-means with k=3 - result is shown on Fig. 4b.
Other example contains stucture of cooper (Fig. 3c.) which requires ASFR of size 1 and k-
means (k=2) - see Fig. 3d.
In examples shown above number of clusters was easy to define a priori. But it is sometimes
in not possible. Number of clusters can be not available a priori. This can happen in scene
analysis. In this case we apply fuzzy version of k-means (FKM).
Fig. 4. (a) input image (scene), (b) ASFR of size 5, (c) FKM k=3, m=3, α=150, (d) FKM k=5,
m=3, α=150.
Image shown in Fig. 4a represents a scene. From the point of view of segmentation it contains
a lot of noise, especially on the right side. ASFR is applied in order to remove possibly lot of
noise. In this case ASFR of size 5 was applied - larger than in examples shown before,
because the structure of noise is more complicated. Filtrated image is presented on Fig. 4b.
Number of clusters can be defined here only roughly. In proposed FKM algorithm some
parameters should be defined. Paramter k represents initial number of clusters. Parmeter m
defines how 'fuzzy' behavior of the algorithm is (the bigger m is, the more 'fuzzy' algorithm
is).
Parameter α indicates threshold for classified pixels. During the experiments the following
parameters were chosen: m equal to 2 or 3, 130<α<190. Segmented images with different
parameters k are shown of Fig. 4c and Fig. 4d. The real number of cluster is in both cases
bigger than defined by parameter k. Result is adapted to the image's structure. In this case
'crisp' k-means would give not 'natural' result - extracted regions would be not good fited to
the real regions on the input image.

CONCLUSIONS

One of the biggest obstacles for applying k-means-like algorithms is always the spectral
nature of this algorithm. It causes problems with bad-classified single points or small areas in
the image. Because of that one should find a supplement that can precede the clustering step,
and which can take under consideration spatial dependencies of the image.
Natural answer to the question of finding such a supplement is filtering. But the most popular
linear filters as well as non-linear (e.g. morphological) have one important disadvantage for
segmentation: they change the shape of the areas on the image. Segmentation by definition
should extract shapes of the areas, so each disturbance of it is a problem.
In order to avoid this, an advanced morphological filtering is proposed: alternating sequential
filter by reconstruction. As it was shown on the attached examples, this solution seems to be
very efficient. It removes local disturbances of graytone without changing the shape of areas.
Also two types of k-means algorithm was applied: traditional version anf fuzzy one. First one
can be applied to the images where number of clusters can be defined by the user. But not in
all cases it can be done. For such a case fuzzy k-means is applied. This variant needs an initial
number of clusters, but during the run of the algorithm this number can change according to
real image content.
Experiments carried out show that proposed combination of advanced morphological filtering
and clustering by k-means and fuzzy k-means considers both spectral and spatial nature of
image and gives good and promising results.

ACKNOWLEDGEMENTS
Authors would like to thank M. Młynarczuk from Instytut Mechaniki Górotworu PAN in
Kraków for the set of geological images.

REFERENCES

S.Beucher. Segmentation d'images et morphologie mathematique. Ph.D. Thesis, School of


Mines of Paris, June 1990.
R.O.Duda, P.E.Hart, Pattern classification and scene analysis. Willey and Sons, 1973.
T.L.Huntsberger, C.L.Jacobs, R.L.Cannon. Iterative fuzzy image segmentation. Pattern
Recognition Vol.18., No.2., pp. 131-138, 1985.
M.Iwanowski. K-means algorithm for greytone reduction. Technical Report, School of Mines
of Paris, N-13/96/MM, 1996.
F.Meyer, S.Beucher. Morphological Segmentation. Journal of Visual Comm. and Image
Representaion. Vol.1, No.1, September, pp. 21-46, 1990.
F.Meyer, J.Serra. Filters: from theory to practice. Acta Stereologica 1989; 8/2; Proceeding of
5-th European Congress for Stereology, Freiburg, September 1989, pp. 503-508.
S.Z Selim, M.A.Ismail. K-means-type algorithms: a generalised convergence theorem and
characterisation of local otimality. IEEE Trans. Patterm Anal. Machine Intell. 6(1), pp.
81-87, 1984.
J.Serra. Image analysis and mathematical morphology. Academic Press, 1982.
J.Serra, ed. Image analysis and mathematical morphology. Volume 2: theoretical advances.
Academic Press, 1988.
J.Serra, L.Vincent. An overview of morphological filtering. Circuits Systems Signal
Processing Vol.11, No.1, 1992.
P.Soille. Partitioning of multispectral images using mathematical morphology. Technical
Report, School of Mines of Paris, N-22/92/MM, 1992.
P.Soille. Geodesic Transformations in Mathematical Morphology: an Overview. Technical
Report, School of Mines of Paris, N-24/94/MM, 1994.
A.Śluzek. Komputerowa analiza obrazu. Wydawnictwa Politechniki Warszawskiej,
Warszawa 1991.
L.Vincent. Morphological Grayscale Reconstruction: Definition, Efficient Algorithm and
Aplications in Image Analysis, IEEE Comp.Vis. and Patt.Rec., Proceedings, 1992,
pp. 622-635

View publication stats

You might also like