Fundamentals of Image Processing
Unit III
Image Segmentation
Dr. Sivadi Balakrishna
Assistant Professor,
Department of CSE, VFSTR.
Department of Computer Science & Engineering 1
Objectives of Image Segmentation
The goal of segmentation is to simplify and/or
change the representation of an image into
something that is more meaningful and easier to
analyze. Image segmentation is typically used to
locate objects and boundaries (lines, curves, etc.)
in images.
The result of image segmentation is a set of
segments that collectively cover the entire image,
or a set of contours extracted from the image.
Each of the pixels in a region are similar with
respect to some characteristic or computed
property, such as color, intensity, or texture.
Department of Computer Science & Engineering 2
Applications of Image Segmentation
Department of Computer Science & Engineering 3
Contents
Fundamentals
Point detection
Line detection
Edge detection
Edge linking via Hough transform
Thresholding
Region based segmentation
Region growing
Region splitting and merging
Segmentation by morphological watersheds
Basic concepts
Dam construction
Watershed segmentation algorithm.
Department of Computer Science & Engineering 4
Fundamentals
Segmentation is a fundamental low-level operation
on images.
The main goal of image segmentation is to divide
an image into parts that have a strong correlation
with objects or areas of the real world contained in
the image.
Boundary detection is the dual goal of image
segmentation.
Extracting information from an image.
Segment the image i.e. to subdivide an image
into its constituent regions or objects.
Department of Computer Science & Engineering 5
Fundamentals
Segmentation is based on two basic properties of
gray-level values:
Discontinuity, i.e. to partition the image
based on abrupt changes in intensity (gray
levels), e.g. edges
Similarity, i.e. to partition the image into
similar (according to predefined criteria)
regions, e.g. Thresholding, region growing,
region splitting and merging
Department of Computer Science & Engineering 6
Fundamentals
Let R represent the entire spatial region occupied
by an image. We may view image segmentation as
a process that partitions R into n subregions, R1,
R2,-----Rn such that
Department of Computer Science & Engineering 7
Point Detection
we know that point detection should be based
on the second derivative which means using
the following Laplacian expressions:
Department of Computer Science & Engineering 8
Point Detection
Previous expression can be implemented using
the following Laplacian kernel
we say that a point has been detected at a
location (x, y) on which the kernel is applied.
If the absolute value of the response of the filter
at that point exceeds a specified threshold. Then
point has been detected.
Department of Computer Science & Engineering 9
Point Detection
Such points are labeled 1 and all others are
labeled 0 in the output image, thus producing a
binary image. In other words, we use the
expression:
where g(x, y) is the output image, T is a
nonnegative threshold, and Z is given by following
equation.
Department of Computer Science & Engineering 10
Point Detection
This formulation simply measures the weighted
differences between a pixel and its 8-neighbors.
Naturally, the idea is that the intensity of an
isolated point will be quite different from its
surroundings, and thus will be easily detectable by
this type of kernel.
Note that, the kernel coefficients sum to zero,
indicating that the filter response will be zero in
areas of constant intensity.
Department of Computer Science & Engineering 11
Line Detection
we know that for line detection we can expect
second derivatives to result in a stronger filter
response, and to produce thinner lines than first
derivatives.
Thus, we can use the following Laplacian kernel
for line detection also.
Department of Computer Science & Engineering 12
Edge Detection
Detecting changes in intensity for the purpose of
finding edges can be accomplished using first- or
second-order derivatives.
The tool of choice for finding edge strength and
direction at an arbitrary location (x, y) of an image,
f, is the gradient, denoted by f and defined as the
vector
The magnitude, M(x, y), of this gradient vector at a
point (x, y) is given by its Euclidean vector norm:
The direction of the gradient vector at a point (x, y)
is given by
Department of Computer Science & Engineering 13
Edge Detection
Gradient Operators
Obtaining the gradient of an image requires
computing the partial derivatives ∂f /∂x and ∂f /∂y
at every pixel location in the image.
These two equations can be implemented for all
values of x and y by filtering f (x, y) with the
following 1-D kernels.
Department of Computer Science & Engineering 14
Edge Detection
Roberts cross-gradient operators
When diagonal edge direction is of interest, we
need 2-D kernels. The Roberts cross-gradient
operators (Roberts [1965]) are one of the earliest
attempts to use 2-D kernels with a diagonal
preference.
Consider the 3 × 3 region in following figure.
Department of Computer Science & Engineering 15
Edge Detection
Roberts cross-gradient operators
The Roberts operators are based on implementing
the diagonal differences
These derivatives can be implemented by filtering
an image with the kernels shown below.
Department of Computer Science & Engineering 16
Edge Detection
Prewitt operators
Kernels of size 2 × 2 are simple conceptually, but
they are not as useful for computing edge direction
as kernels that are symmetric about their centers,
the smallest of which are of size 3 × 3.
The simplest digital approximations to the partial
derivatives using kernels of size 3 × 3 are given by
The difference between the third and first rows of
the 3 × 3 region approximates the derivative in the
x-direction, and the difference between the third
and first columns approximate the derivative in
the y-direction.
Department of Computer Science & Engineering 17
Edge Detection
Prewitt operators
Intuitively, we would expect these
approximations to be more accurate than the
approximations obtained using the Roberts
operators.
Robert and Prewitt Equations can be
implemented over an entire image by filtering it
with the following two kernels.
Department of Computer Science & Engineering 18
Edge Detection
Sobel Operators
A slight variation of the preceding two equations
uses a weight of 2 in the center coefficient:
It can be demonstrated that using a 2 in the
center location provides image smoothing.
Following figures show the kernels used to
implement above equations.
Department of Computer Science & Engineering 19
Thresholding
Foundation
One obvious way to extract the objects from the
background is to select a threshold, T, that
separates these modes.
Then, any point (x, y) in the image at which f (x, y)
> T is called an object point. Otherwise, the point is
called a background point.
In other words, the segmented image, denoted by
g(x, y), is given by
Department of Computer Science & Engineering 20
Thresholding
Figure shows a more difficult thresholding problem
involving a histogram with three dominant modes
corresponding, for example, to two types of light
objects on a dark background.
Here, multiple thresholding classifies a point (x, y)
as belonging to the background if f (x, y) ≤ T1, to
one object class if T1<f(x, y) ≤T2, and to the other
object class if f (x, y) > T2.
That is, the segmented image
is given by
Department of Computer Science & Engineering 21
Basic Global Thresholding
When the intensity distributions of objects and
background pixels are sufficiently distinct, it is
possible to use a single (global) threshold
applicable over the entire image.
This algorithm can estimate the threshold value
for each image is required.
The following iterative algorithm can be used for
this purpose:
1. Select an initial estimate for the global
threshold, T.
2. Segment the image using T in below Equation.
Department of Computer Science & Engineering 22
Basic Global Thresholding
This will produce two groups of pixels: G1,
consisting of pixels with intensity values > T;
and G2 , consisting of pixels with values ≤ T.
3. Compute the average (mean) intensity values
m1 and m2 for the pixels in G1 and G2,
respectively.
4. Compute a new threshold value midway
between m1and m2 :
T = 1/2(m1 + m2)
5. Repeat Steps 2 through 4 until the difference
between values of T in successive iterations is
smaller than a predefined value, T.
Department of Computer Science & Engineering 23
Optimum Global Thresholding
Otsu’s algorithm may be summarized as follows:
1. Compute the normalized histogram of the input
image. Denote the components of the histogram
by , i, = 0, 1, 2,…, L− 1.
2. Compute the cumulative sums, , for k = 0, 1, 2,
…, L − 1, using below Equation.
3. Compute the cumulative means, m(k), for k = 0,
1, 2,…, L − 1, using below Equation.
Department of Computer Science & Engineering 24
Optimum Global Thresholding
4. Compute the global mean, , using below
Equation.
5. Compute the between-class variance term,, for k
= 0, 1, 2,…, L − 1, using below Equation.
6. Obtain the Otsu threshold, k*, as the value of k
for which is is maximum. If the maximum is not
unique, obtain k* by averaging the values of k
corresponding to the various maxima detected.
Department of Computer Science & Engineering 25
Optimum Global Thresholding
7. Compute the global variance, , using below first
Equation, and then obtain the separability
measure,, by evaluating below second Equation
with k = k*
Department of Computer Science & Engineering 26
Optimum Global Thresholding
Example:
Intensity(i) 0 1 2 3 4 5 6 7
No.of Pixels 0 10 0 0 20 0 12 8
Pi 0 0.2 0 0 0.4 0 0.24 0.16
P1(k);k=0…7 0 0.2 0.2 0.2 0.6 0.6 0.84 1
m(k);k=0…7 0 0.2 0.2 0.2 1.8 1.8 3.24 4.36
4.36 - - - - - - -
;k=0…7 0 2.822 2.822 2.822 2.774 2.774 1.328 0
K* 2 - - - - - - -
4.07 - - - - - - -
𝜂(k) 0.693 - - - - - - -
Department of Computer Science & Engineering 27
Region Based Segmentation
Let R represent the entire spatial region occupied
by an image. We may view image segmentation as
a process that partitions R into n subregions, R1,
R2,-----Rn such that
Department of Computer Science & Engineering 28
Region Growing
As its name implies, region growing is a procedure
that groups pixels or subregions into larger
regions based on predefined criteria for growth.
The basic approach is to start with a set of “seed”
points, and from these grow regions by appending
to each seed those neighboring pixels that have
predefined properties similar to the seed (such as
ranges of intensity or color).
Let: f (x, y) denote an input image; S(x, y) denote a
seed array containing 1’s at the locations of seed
points and 0’s elsewhere; and Q denote a predicate
to be applied at each location (x, y).
Department of Computer Science & Engineering 29
Region Growing
A basic region-growing algorithm based on 8-connectivity
may be stated as follows
1. Find all connected components in S(x, y) and reduce
each connected component to one pixel; label all such
pixels found as 1. All other pixels in S are labeled 0.
2. Form an image such that, at each point (x, y), (x , y) =
1 if the input image satisfies a given predicate, Q, at
those coordinates, and (x , y) = 0 otherwise.
3. Let g be an image formed by appending to each seed
point in S all the 1-valued points in that are 8-
connected to that seed point.
4. Label each connected component in g with a different
region label.
Department of Computer Science & Engineering 30
Region Splitting and Merging
Let R represent the entire image region and select
a predicate Q.
One approach for segmenting R is to subdivide it
successively into smaller and smaller quadrant
regions so that, for any region Ri ,Q(Ri ) = TRUE.
Department of Computer Science & Engineering 31
Region Splitting and Merging
We start with the entire region, R. If Q(R) =
FALSE, we divide the image into quadrants.
If Q is FALSE for any quadrant, we subdivide that
quadrant into sub-quadrants, and so on.
If only splitting is used, the final partition
normally contains adjacent regions with identical
properties. This drawback can be remedied by
allowing merging as well as splitting.
merging only adjacent regions whose combined
pixels satisfy the predicate Q. That is, two
adjacent regions Rj and Rk are merged only if
Q( Rj U Rk ) = TRUE.
Department of Computer Science & Engineering 32
Segmentation by morphological watersheds
Department of Computer Science & Engineering 33
Segmentation by morphological watersheds
Department of Computer Science & Engineering 34
Segmentation by morphological watersheds
Department of Computer Science & Engineering 35
Segmentation by morphological watersheds
Department of Computer Science & Engineering 36
Segmentation by morphological watersheds
Department of Computer Science & Engineering 37
Segmentation by morphological watersheds
Department of Computer Science & Engineering 38
Segmentation by morphological watersheds
Department of Computer Science & Engineering 39
Segmentation by morphological watersheds
Department of Computer Science & Engineering 40
Segmentation by morphological watersheds
Department of Computer Science & Engineering 41
Segmentation by morphological watersheds
Department of Computer Science & Engineering 42
Segmentation by morphological watersheds
Department of Computer Science & Engineering 43
Segmentation by morphological watersheds
Department of Computer Science & Engineering 44
Segmentation by morphological watersheds
Department of Computer Science & Engineering 45
Segmentation by morphological watersheds
Department of Computer Science & Engineering 46
Segmentation by morphological watersheds
Department of Computer Science & Engineering 47
Segmentation by morphological watersheds
Department of Computer Science & Engineering 48
The End
Department of Computer Science & Engineering 49