Morphological Processing
Morphological Processing
Tariq Al-Juboori
Morphological processing
1. Introduction :
The word morphology signifies the study of the form or structure.
Mathematical morphology is a tool used for extracting image components
based on properties of form or shape within the image.
The language of Mathematical morphology is set theory.
A unified and powerful method to solve numerous processing problems.
1
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
Figure 1. The binary image depicted above contains two objects (groups of connected pixels)
under 8-connectedness but three objects under 4-connectedness
Example 1-: A (8x8) binary image is given below, which objects of the foreground
pixel values give 4-and 8-connected?
Properties of interest in binary images are the shape, size and location of the
objects in the image.
Foreground or background pixel has its value changed depending on three
things; Two of them are the image and the type of morphological operation.
The third factor is called the structuring element and is a key element in any
morphological operation.
2
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
figure below.
6
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
·The art in morphological processing is to choose the structuring element to suit the application or
the required aim.
6
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
6
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
6
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
shown below;
6
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
Example 4:- Repeat example (3) with new structuring elements as shown below;
6
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
A B
Solution:
6
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
Figure 5. Using dilation and erosion to identify features based on shape: (a) original; (b)
result after thresholding; (c) After erosion with horizontal line, (d) after erosion with
vertical line,(e) after dilation with same vertical and horizontal lines, (f) boundary of
remaining objects superimposed on original
6
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
Figure 6.Using repeated erosion and object counting to estimate the distribution of
particle sizes:
(a) original image; (b) binary image resulting from intensity thresholding; (c) estimated
cumulative
6
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
(
A B)
B=
B
A
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 1 0 0 0 1 1 1 0
0 0 0 0 0 0 0 1 0 0
6
0 0 0 0 0 0 0 0 0 0
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
Example 6:-What is the closing morphological operation. Apply application areas of each of them. Consider
the binary image and structuring element as shown below;
0 0 0 0 0 0
0 0 1 0 0 0
0 1 1 1 1 0
0 0 1 0 0 0
0 0 0 0 0 0
AB
Solution:
0 0 1 1 0 0 0 0 0 0 0 0
A B= (A B)
0 1 1 1 1 0 0 0 1 1 0 0
B=
0 1 1 1 1 0 0 1 1 1 1 0
0 1 1 1 1 0 14 0 0 1 1 0 0
0 0 1 1 0 0 0 0 0 0 0 0
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
Figure 7. The opening of object A by structuring element B, AoB (left). The closing of object A by
14
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
Figure 8. Illustrating the effects of opening and closing upon some example shapes. The original image
shown in the center was opened using disk-shaped structuring elements of radii 3, 5 and 15 pixels,
producing the images to the left. The images to the right were similarly produced by closing the image using
the same structuring elements. The differences become more pronounced the larger the structuring element
employed.
9. Boundary extraction
The boundary can be defined of an object by first eroding the object with a suitable small
structuring element and then subtracting the result from the original image .Thus ,for a
binary image A and a structuring element B, the boundary Ap is defined as:
Ap= A−( A Θ B)
Figure .9 Boundary extraction. Left: original.; center: single-pixel boundary; right:thick boundary
17
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
10. Extracting connected components: The set of all pixels which are connected to a
given pixel is called the connected component of that pixel. The process of extracting
connected components leads to a new image in which the connected groups of pixels (the
objects) are given sequential integer values: the background has value 0, the pixels in the
first object have value 1, the pixels in the second object have value 2 and so on. To identify
and label 8-connected components in a binary image, we proceed as follows:
Scan the entire image by moving sequentially along the rows from top to bottom.
Whenever we arrive at a foreground pixel p we examine the four neighbors of p
which have already been encountered thus far in the scan. These are the neighbor’s (i)
to the left of p, (ii) above p, (iii) the upper left diagonal and (iv) the upper right
diagonal.
. if all four neighbors are background (i.e. have value 0), assign a new label to p; else
. if only one neighbour is foreground (i.e. has value 1), assign its label to p; else
. if more than one of the neighbours is foreground, assign one of the labels to p and resolve
the equivalences.
Let A denote our image, x o be an arbitrary foreground pixel identified at the beginning of
the procedure, x k the set of connected pixels existing at the kth iteration and B be a
The algorithm thus starts by dilating from a single pixel within the connected component
using the structuring element B. At each iteration, the intersection with A ensures that no
17
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
pixels are included which do not belong to the connected component. When we reach the
point at which a given iteration produces the same connected component as the previous
iteration (i.e. x k =x k 1), all pixels belonging to the connected component have been found.
Figure 8.12 Connected components labelling. The image displayed on the left is a binary image
containing five connected components or objects. The image displayed on the right is a ‘label matrix’
in which the first group of connected pixels is assigned a value of 1, the second group a value of 2 and
Let B be a structuring element and let x o be a ‘seed’ background pixel lying within the hole.
Setting x o to be foreground (value 1) to initialize the procedure, the hole may be filled by
applying the following iterative expression:
17
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
The filled region is then obtained as A U x k . The algorithm thus works by identifying a point
( x o) within the hole and then growing this region by successive dilations. After each dilation,
we take the intersection (logical AND) with the logical complement of the object A. When
the region has grown to the extent that it touches the boundary at all points, the next iteration
will grow the region into the boundary itself. However, the intersection with A will produce
the same pixel set as the previous iteration, at which point the algorithm stops.
In the final step, the union of A with the grown region gives the entire filled object. The
complete set of pixels belonging to all holes is then obtained as The seed
pixels x o for the hole-filling procedure described by Equation (8.3) can
thus be obtained by:
(iii) removing the set of filled pixels resulting from step (ii) from H; (iv) repeating (i)–(iii)
until H is empty.
17
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
Figure 8.13 The hit-or-miss transformation. The aim is to identify those locations within an image
(right) at which the specified target configuration of pixels or target shape (left) occurs.
Figure 8.14 The hit-or-miss transformation. The first step is erosion of the image by the target
Figure 8.15. show the logical complement of image A together with a target pixel
configuration B2 which is the logical complement of B1 (i.e. B2= B1).
Consider now applying erosion of the image complement A by the complement of the target
shape B2. By definition, this erosion will preserve all those pixels at which the foreground
pixels of the target complement B2 can be entirely contained within the foreground pixels of
the image complement A. These points are indicated in Figure 8.16
17
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
Figure 8.15 The hit-or-miss transformation. For the second step where we locate the misses, we
consider the complement of the image A and the complement of the target shape B2 = B1
Figure 8.16 The hit-or-miss transformation. The second step consists of eroding the complement of
the image A by the complement of the target shape (B2 = B1). This produces the misses denoted here
by crosses.
as crosses and are designated as ‘misses’. Note, however, that because we have carried out
the erosion using the complements of the target and image. Second step logically translates
to the identification of all those locations at which the background pixel configuration of the
target is entirely contained within the background of the image. The misses thus identify all
locations at which the correct configuration of background pixels are found but does not test
for the required configuration of foreground pixels.
The first step has identified all those points in the image foreground at which the required
configuration of foreground pixels in the target may be found (but has ignored the required
background configuration). By contrast, the second step has identified all those points in
the image background at which the required configuration of background pixels in the target
17
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
may be found (but has ignored the required foreground configuration). Third step take a
logical intersection (AND) of the two images. Thus, the hit-or-miss transformation of A by
B1 is formally defined as:
The result obtained for our example is indicated in Figure 8.17. The sole surviving pixel
(shaded) gives the only location of the target shape to be found in the image.
Figure 8.17 The hit-or-miss transformation. The final step takes the intersection (logical AND) of
the two eroded images . Any surviving pixels give the location of the target shape in the original image A.
Figure 8.18 illustrate the use of the hit-and-miss transform to identify the occurrences of a
target letter ‘e’ in a string of text.
Figure 8.18 Application of the hit-or-miss transformation to detect a target shape in a string of
text. Note that the target includes the background and hit-or-miss is strictly sensitive to both the
scale and the orientation of the target shape (See colour plate section for colour version).
17
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
This means that only exact examples of the target shape (including background and
foreground pixel configurations) are identified. If even one pixel of the configuration probed
in the image differs from the target shape, then the hit-or-miss transform we have used will
not identify it (see Figure 8.19).
Figure 8.19 The fully constrained hit-or-miss transform is sensitive to noise and uncontrolled
variations in the target feature. In the example above, three instances of the target letter .e. on the
second line were missed due to the presence of a small amount of random noise in the image.
(1) A strict definition which requires that an ‘upper right corner pixel’ must have no
neighbours to north, north-west, north-east or east (these are the misses) and must have
17
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
neighbours to the south and west (these are the hits). The south-west neighbour is neither hit
nor miss and, thus, a don’t care pixel.
(2) A looser definition which only requires that an upper right corner pixel must have no
neighbours to north, north-west and north-east (the misses). All other neighbours are
Figure 8.20 Generalizing the hit-or-miss transform. This illustrates the effect of relaxing constraints
on the hit-or-miss transform. Top left: original image. Top right and bottom left (which uses
an alternative computation): the result of hit-or-miss for strict definition of upper right corner pixels –
only the upper right corner pixels of the solid L shapes are identified. Bottom right: in the second
17
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
14. Skeletonization
A very useful conceptualization of the morphological skeleton is provided by the prairie-fire
analogy: the boundary of an object is set on fire and spreads with uniform velocity in all
directions inwards; the skeleton of the object will be defined by the points at which the fire
fronts meet and quench (i.e. stop) each other.
Consider an arbitrary, binary object A. A point p within this binary object belongs to the
skeleton of A if and only if the two following conditions hold:
(1) A disk Dz may be constructed, with p at its center, that lies entirely within A and touches
the boundary of A at two or more places.
(2) No other larger disk exists that lies entirely within A and yet contains D z.
(1) Start at an arbitrary point on the boundary and consider the maximum possible size of
disk which can touch the boundary at this point and at least one other point on the boundary
and yet remain within the object.
(2) Mark the Centre of the disk.
(3) Repeat this process at all points along the entire boundary (moving in infinitesimal steps)
until you return to the original starting point. The trace or locus of all the disk center points is
the skeleton of the object.
Figure 8.21 shows a variety of different shapes and their calculated skeletons. should
convince that the circle is actually slightly elliptical and that the pentagon and star are not
regular. The skeleton is a useful representation of the object morphology, as it provides both
topological information and numerical metrics which can be used for comparison and
categorization.
17
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
Figure 8.22 Effects of morphological opening. (a) Original binary image. (b) Result of opening
using a circular structuring element of radius 10. Note the rounding on the points of the star and the
corners of the rectangle. (c) Result of opening using a square structuring element of side length 25.
Only the rectangle is properly restored, the other shapes are significantly distorted.
17
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
17
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
Figure 8.24 Calculating the morphological gradient: (a) grey-scale dilation with flat 3_3
structuring element; (b) grey-scale erosion with flat 3_3 structuring element; (c) difference of
(a) and (b)= morphological gradient.
19. Grey-scale opening and closing
Grey-scale opening and closing are defined in exactly the same way as for binary images and
their effect on images is also complementary. Grey-scale opening (erosion followed by
dilation) tends to suppress small bright regions in the image whilst leaving the rest of the
image relatively unchanged, whereas closing (dilation followed by erosion) tends to suppress
small dark regions. We can exploit this property in the following example, in Figure 8.25 in
which the objects/regions of interest are of similar size and separated from one another,
opening can be used quite effectively to estimate the illumination function.
Figure 8.25 Correction of nonuniform illumination through morphological opening. Left to right:
(a) original image; (b) estimate of illumination function by morphological opening of original;
(c) original with illumination subtracted; (d) contrast-enhanced version of image (c)
17
Lecture No.:7 Digital Image Processing Asst. Prof.Dr. Tariq Al-Juboori
Figure 8.26 Morphological top-hat filtering to increase local image detail. Left to right: (a) original
image; (b) after application of top-hat filter (circular structuring element of diameter approximately
equal to dimension of grains); (c) after contrast enhancement
17