DIP Module4
DIP Module4
Aug 6, 2025 1
Image Segmentation
• Introduction:
• So far we saw image processing methods whose input and output are images,
but now let us see those methods in which the inputs are images, but the
outputs are attributes extracted from those images
• The level to which the subdivision is carried depends on the problem being
solved.
• Segmentation should stop when the objects of interest have been isolated.
Aug 6, 2025 2
• Segmentation accuracy determines the eventual success or failure of
computerized analysis procedures.
Aug 6, 2025 3
Image Segmentation
• In industrial inspection applications, at least some measure of control over the environment is
possible at times.
• The experienced image processing system designer invariably pays considerable attention to such
opportunities.
• Let 𝑅 represent the entire image. Segmentation is a process that divides 𝑅 into 𝑛 subregions 𝑅1 , 𝑅2 ,
… , 𝑅𝑛 such that:
• 1. 𝑅𝑖 𝑛 𝑖=1 = 𝑅.
• 5. 𝑄 𝑅𝑖 ∪ 𝑅𝑗 = 𝐹𝐴𝐿𝑆𝐸 for any adjacent regions 𝑅𝑖 and 𝑅𝑗 . Here 𝑄 𝑅𝑘 is a predicate that indicates
Aug 6, 2025 4
Image Segmentation
• In other applications, such as autonomous target acquisition, the system designer
has no control of the environment.
• Then the usual approach is to focus on selecting the types of sensors which could
enhance the objects of interest while diminishing the contribution of irrelevant
image detail.
• E.g. : the use of infrared imaging by the military to detect objects with strong
heat signatures, such as equipment and troops in motion.
Aug 6, 2025 5
Image Segmentation
• Image segmentation algorithms are based on one of two basic properties of intensity
values:
• Discontinuity and
• Similarity.
• Discontinuity:
• Similarity:
• These are based on partitioning an image into regions that are similar according to a set
of predefined criteria. Aug 6, 2025 6
• The segmentation algorithms for monochrome images are based on either
discontinuity or similarity of pixel intensities
• In the second category, idea is to partition the image into regions that are
similar according to a set of predefined criteria.
Aug 6, 2025 8
• (a) shows an image having a region of constant intensity superimposed on darker
background.
• (b) shows the result of computing boundary of the inner region based on intensity
discontinuity
• Points inside and outside the boundary are zero because there are no discontinuities
in those regions.
• To segment the image, we assign one level (say white) to the pixels on or interior
to boundary and another level (black) to the pixels exterior to boundary
Aug 6, 2025 9
Image Segmentation
Aug 6, 2025 10
• Next figure shows the result of computing edges of the previous image
Aug 6, 2025 11
• We may compute standard deviation of pixels to achieve this
• The original image may be subdivided into region of 4X4 and labeled white if
the SD of the pixels are positive and zero otherwise.
Aug 6, 2025 12
• We know local changes in intensity can be detected using derivatives.
Aug 6, 2025 13
• Background:
• Basics of derivatives
• The rules to be satisfied
• Equations for first and second order derivatives
• E.g.:
Aug 6, 2025 14
Image Segmentation
Aug 6, 2025 15
Image Segmentation
• Figure has
• Solid objects, straight line and single noise point
• Horizontal Intensity profile of a scan line is shown in (b)
• We can notice ramp edges and step edges
• (c) shows how simplified view of profile to analyze numerically how 1 st and 2nd
order derivatives behave as they encounter noise point, line and edge
• Transition in ramp – 4 pixel,
• Transition on noise point – 1 pixel
• Transition on line 3 - pixels and
• Transition on step – adjacent pixels
• By using the properties of derivatives we can see that, first order derivative is non-
zero at the onset and along the ramp
Aug 6, 2025 16
• 2nd order derivative is non-zero only at the onset and end of the ramp
• Since the edges of digital images show this type of transition, we can say that 1st order
derivatives produce thick edges and second order derivatives produce fine edges
• For noise point, magnitude of 2nd order derivative is larger than 1st order derivative
• Reason is 2nd order derivatives are more capable of enhancing fine details
• Similar arguments hold good for line which is also thin in this case
• 2nd order derivative in both ramp and step has opposite signs as it transitions into and
out of edge.
• Edge pixels are those at which intensity of an image function changes abruptly
• Edge detectors - local image processing methods used to detect edge pixels
Aug 6, 2025 18
• Detection of Discontinuities:
Three basic types of gray-level discontinuities in a digital image:
points,lines, and edges
• The most common way to look for discontinuities is to run a mask through the image
is by computing the sum of products of the coefficients with the gray levels
contained in the region encompassed by the mask,
• where Zi is the gray level of the pixel associated with mask coefficient W i
Aug 6, 2025 19
• Detection of isolated points
• Point detection could be based on 2nd derivative
• So we can use Laplacian equation seen earlier
Aug 6, 2025 20
• Then the Laplacian will be
• This expression can be implemented using the mask (a) shown below
• we say that a point has been detected at the location on which the
mask is centered if
|R| > T
where T is a nonnegative threshold and R is given by
Aug 6, 2025 22
• Basically, this formulation measures the weighted differences between
the center point and its neighbors.
Aug 6, 2025 23
• The output is obtained by using the expression
Aug 6, 2025 24
• The Laplacian mask is as shown below
• Using this mask we can say that a point is detected at location (x, y) on which mask
is centered, if the absolute value of the response of the mask at that point exceeds the
specified threshold.
• All such points are labeled as 1 and all other are with 0 resulting in binary image
Aug 6, 2025 25
• Line detection:
• We have seen that, second order derivative produces stronger response and could
result in thinner line than 1st order derivative.
• Thus we can use Laplacian mask used for point detection here also
• But care is to be given to handle the double line effect similar to double edge of
point detection
Aug 6, 2025 26
• Laplacian mask seen earlier is isotropic- its response is independent of
directions (vertical, horizontal and two diagonals)
• But in reality lines may not be always in these four directions
• Consider the following masks
Aug 6, 2025 27
• Suppose that an image with constant background, containing various lines.
• If the first mask were moved around an image, it would respond more
strongly to lines (one pixel thick) oriented horizontally.
Aug 6, 2025 28
• Similarly second mask gives best response to line which are oriented +45°,
third mask for vertical lines and last mask for -45°.
• Let Rl, R2 , R3 , and R4 denote the responses of the masks in Fig. from left to
right, where the R's are given by
Aug 6, 2025 29
• Suppose that the four masks are run individually through an image.
• If, at a certain point in the image, |Ri| > |Rj|, for all j != i, that point is said to be
more likely associated with a line in the direction of mask i.
Aug 6, 2025 30
• E.g.:
• if at a point in the image, |R1|> |Rj| for j = 2, 3, 4 that particular point is said to
be more likely associated with a horizontal line.
• In this case, we would use the mask associated with that direction and
threshold its output as per the equation .
Aug 6, 2025 31
• In other words, if we are interested in detecting all the lines in an image in
the direction defined by a given mask, we run the mask through the image
and threshold the absolute value of the result.
Aug 6, 2025 32
• Edge detection:
• Edge models:
• Classified according to their intensity profiles
• Step edge: transition between two intensities occur ideally over a distance of
one pixel
• Figure below shows the section of vertical step edge and horizontal intensity
profile along the edge
Aug 6, 2025 33
• Ramp edge: In practice, images contain edges that are blurred and noisy
• Degree of blurring depends on focusing mechanism such as lenses and degree of noise
depends on electronic components of imaging system
• Instead, edge point is any point contained in the ramp and edge segment would be set
of connected edge points.
• This makes sense: Blurred edges tend to be thick and sharp edges tend to be thin.
Aug 6, 2025 34
• Roof edge: These have characteristics as shown in figure below
• These are models of lines through a region with base of the roof edge is determined
by the thickness and sharpness of the line
• If the base thickness is 1 pixel, then edge will be one line running through the region
• E.g.: in range imaging, when thin objects are closer to the sensors than the
background. ( pipe and wall- pipes appear bright and create
Aug 6, 2025 35
• Note that, single image may contain all three types of edges
• There may be a little deviation from the ideal shape due to noise and blurring
Aug 6, 2025 36
• Figure 10.6(b) shows a horizontal gray-level profile of the edge
between the two regions.
• This figure also shows the first and second derivatives of the gray-
level profile.
• The first derivative is positive at the points of transition into and out of
the ramp as we move from left to right along the profile: it is constant
for points in the ramp: and is zero in areas of constant gray level.
Aug 6, 2025 37
• The second derivative is positive at the transition associated with
the dark side of the edge, negative at the transition associated with
the light side of the edge, and zero along the ramp and in areas of
constant gray level.
Aug 6, 2025 38
Aug 6, 2025 39
• We conclude from these observations that the magnitude of the first
derivative can be used to detect the presence of an edge at a point in an
image (i.e.. to determine if a point is on a ramp).
Aug 6, 2025 40
• We note two additional properties of the second derivative around an edge:
(1) It produces two values for every edge in an image (an undesirable
feature):
and
(2) an imaginary straight line joining the extreme positive and negative values
of the second derivative would cross zero near the midpoint of the edge. This
zero-crossing property of the second derivative is quite useful for locating the
centers of thick edges
Aug 6, 2025 41
• Basic Edge Detection
• Gradient operators:
• The image gradient is used to find edge strength and direction at location (x,y) of
image, and defines as the vector.
Aug 6, 2025 42
• The magnitude(length)of vector ,denoted as M(x,y)
• This quantity gives the maximum rate of increase of f(x, y) per unit distance in the direction
of . It is a common (although not strictly correct) practice to refer to also as the
gradient.
• Let the 3 x 3 area shown below represent the gray levels in a neighborhood
of an image.
Aug 6, 2025 44
• one of the simplest ways to implement a first-order partial derivative at
point z5, is to use the following Roberts cross-gradient operators:
• In this formulation, the difference between the first and third rows of the 3
X 3 image region approximates the derivative in the x-direction,
• and the difference between the third and first columns approximates the
derivative in the y-direction.
Aug 6, 2025 46
• The masks called the Prewitt operators, can be used to implement these
two equations.
Aug 6, 2025 47
• A slight variation of these two equations uses a weight of 2 in the center
coefficient:
Gx =(z7 + 2z8 + z9) - (z1 + 2z2 + z3)
And
Gy =(z3 + 2z6 + z9) - (z1 + 2z4 + z7)
Aug 6, 2025 49
• In the previous discussion, we just discuss to obtain the Gx and Gy.
(1) Using its zero-crossing property for edge location, as mentioned earlier
in this section,
Aug 6, 2025 53
• The Laplacian
• For these reasons, the role of the Laplacian in segmentation consists of
(1) Using its zero-crossing property for edge location, as mentioned earlier
in this section,
Aug 6, 2025 54
• Advanced Edge detection
• The basic edge detection method is based on simple filtering without
taking note of image characteristics and other information.
• More advanced techniques make attempt to improve the simple
detection by taking into account factors such as noise, scaling etc.
• We introduce 2 techniques:
• Marr-Hildreth Edge Detector
• Canny Edge detector
Aug 6, 2025 55
• Marr and Hildreth argued that:
• Intensity of changes is not independent of image scale
• Sudden intensity change will cause a zero crossing of the second derivative
• Therefore, an edge detection operator should:
Be capable of being tuned to any scale
Be capable of computing the first and second derivatives
Aug 6, 2025 56
• The Marr-Hildreth edge detector/ Laplacian of Gaussian/
Mexican hat function
• Because these are linear process, the above equation can be written
also as
Aug 6, 2025 58
• It’s edge-detection algorithm may be summarized as follow:
1. Filter the input image with an n x n Gaussian lowpass filter (It can
smooth the large numbers of small spatial details).
Aug 6, 2025 59
The Canny Edge Detector
• Three basic objectives:
1.Low error rate – Edge detected must be as close as possible to the true
edge.
2.Edge points should be well localized—The edges located must be as close
as possible to the true edges.ie the distance between a point marked as an
edge by the detector and the centre of the true edge should be minimum.
3.Single edge point response – The detector should return only one point for
each true edge point.ie number of local maxima around the true edge
should be minimum.The detector should not identify multiple edge pixels
where only a single edge point exists.
Aug 6, 2025 60
• Canny Edge algorithm consists of the following steps
1.Smooth the input image with a Gauussian filter.
2.Compare the Gradient magnitude and angle images.
3.Apply Nonmaxximum supression to the gradient magnitude image
4.Use double thresholding and connectivity analysis to detect and link edges.
Aug 6, 2025 61
• Step 2 – Compute Gradient
• locate the edges using direction of the point with the same method as
basic edge detection – gradient:
• Let 𝑇𝐿 , 𝑇𝐻 be low and high thresholds. The suggested ratio is 1:3 or 2:3.
• We will reduce them using hysteresis (or double) thresholding.
Aug 6, 2025 64
• Edge Linking and Boundary Detection
• Ideally, the methods discussed in the previous section should yield pixels lying
only on edges.
Aug 6, 2025 65
• Local processing
• This edge linking is to analyze the characteristics of pixels in a small
neighborhood about every point(x,y) that has been declared an edge point by
previous techniques.
• The two principle properties used for establishing similarity of edge pixels are
1. the strength of the response of the gradient operator used to produce the edge
pixel
2. the direction of the gradient vector.
Aug 6, 2025 66
• Thus an edge pixel with coordinates (x0, y0) in a predefined neighborhood of (x, y) is
similar in magnitude to the pixel at (x, y) if
• An edge pixel at (x0, y0) in the predefined neighborhood of (x, y) has an angle similar to
the pixel at (x. y) if
Aug 6, 2025 68
Edge Linking and Boundary Detection
Local Processing: Example
In this example,
we can find the
license plate
candidate after
edge linking
process.
• Regional processing
• Often, the location of regions of interest in an image are known or can be
determined.
• In such situations ,we can use techniques for linking pixels on a regional basis,
with the desired result being an approximation to the boundary of the region.
• Then compute the perpendicular distance from all other points in the curve to
this line and select the point that yielded maximum distance.
Aug 6, 2025 71
• Lines from A to C and from C to B are then established, and distances from all
the points between A and C to line AC are obtained.
Aug 6, 2025 72
Global processing using the Hough transform
• One possible solution is to first find all lines determined by every pair of
points and
• then find all subsets of points that are close to particular lines.
Aug 6, 2025 76
Global processing using the Hough transform
• The problem with this procedure is that it involves finding n(n - 1)/2
(approx. n2 ) lines and then performing (n)(n(n - 1))/2 (approx. n3)
comparisons of every point to all lines.
Aug 6, 2025 77
Global processing using the Hough transform
• The problem with this procedure is that it involves finding n(n - 1)/2
(approx. n2 ) lines and then performing (n)(n(n - 1))/2 (approx. n3)
comparisons of every point to all lines.
Aug 6, 2025 78
Aug 6, 2025 79
Global processing using the Hough transform
• Consider a point (xi, yi) and the general equation of a straight line in slope-intercept
form, yi = axi + b.
• Infinitely many lines pass through (xi, yi) ,but they all satisfy the equation yi = axi +
b. for varying values of a and b.
• However, writing this equation as b = -xia + yi, and considering the ab-plane (also
called parameter space) yields the equation of a single line for a fixed pair (x i, yi)
Aug 6, 2025 80
Aug 6, 2025 81
Global processing using the Hough transform
• Furthermore, a second point (xj ,yj) also has a line in parameter space associated with
it, and this line intersects the line associated with (x i, yi) at (a', b'), where a' is the
slope and b' the intercept of the line containing both (xi, yi) and (xj ,yj) in the xy-
plane.
• In fact, all points contained on this line have lines in parameter space that intersect at
(a', b').
Aug 6, 2025 82
Aug 6, 2025 83
• At the end of this procedure, a value of Q in A(i, j) corresponds to Q points
in the xy-plane lying on the line y = aix + bj .
Aug 6, 2025 84
Global processing using the Hough transform
• One way around this difficulty is to use the normal representation of a line:
Aug 6, 2025 85
Aug 6, 2025 86
Edge Linking and Boundary Detection
Hough Transform Example
The intersection of the curves
corresponding to points 1,3,5
2,3,4
1,4
Aug 6, 2025 88
Global processing using the Hough transform
3. Examine the counts of the accumulator cells for high pixel concentrations.
5. Link these pixels if the gaps are smaller than the threshold.
Aug 6, 2025 89
Global Processing via Graph-Theoretic Techniques
Aug 6, 2025 90
• We begin the development with some basic definitions.
• A graph in which the arcs, are directed is called a directed graph, If an arc
is directed from node ni, to node nj.
Aug 6, 2025 91
Aug 6, 2025 92
Global processing Via Graph
Theoretic Techniques
• A global approach for edge detection and linking
based on representing edge segments in the form of a
graph and searching the graph for low-cost paths that
correspond to significant edges.
• This representation provides a rugged approach that
performs well in the presence of noise.
• As might be expected,the procedure is considerably
more complicated and requires more processing time
than the methods discussed so far.
Aug 6, 2025 93
Aug 6, 2025 94
Aug 6, 2025 95
A 3x3 Image region
Aug 6, 2025 96
Aug 6, 2025 97
Aug 6, 2025 98
Aug 6, 2025 99
Aug 6, 2025 100
Aug 6, 2025 101
Aug 6, 2025 102
Aug 6, 2025 103
Aug 6, 2025 104
Region-Based Segmentation
• Segmentation techniques that are based on finding the regions directly.
• Basic Formulation
• Let R represent the entire image region.
• We may view segmentation as a process that partitions R into n subregions,
R1 , R2, ... , Rn , such that
• Condition (b) requires that points in a region must be connected in some predefined sense
• Condition (d) deals with the properties that must be satisfied by the pixels in a segmented
region-for example
• P( Ri,) = TRUE if all pixels in Rj have the same gray level. Finally, condition
• (e) indicates that regions Ri, and Rj, are different in the sense of predicate P.
• 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
properties similar to the seed.
• Step2. The region are grown from these seed points to adjacent point
depending on a threshold or criteria(8-connected) we make.
• Step3. Region growth should stop when no more pixels satisfy the criteria
for inclusion in that region
• Advantages :
• 1. Region growing methods can correctly separate the regions that have the same properties
we define.
• 2. Region growing methods can provide the original images which have clear edges the good
segmentation results.
• 3. The concept is simple. We only need a small numbers of seed point to represent the
property we want, then grow the region.
• It performs well with respect to noise, which means it has a good shape matching of its result.
• 2. This method may not distinguish the shading of the real images.
• In conclusion, the region growing method has a good performance with the good shape
matching and connectivity. The most serious problem of region growing method is the
time consuming.
• We can split the image by choosing the criteria we want, such as segment
variance or mean of the pixel-value. And the splitting criteria can be different
from the merging criteria.
• Disadvantage of it :
1. Computation is intensive.
• The blocky segment problem effect can be reduce by splitting for higher
resolution, but at the same time, the computational problem will be more serious.
Aug 6, 2025 114
Then any point (x, y) for which f( x, y) > T is
called an object point; otherwise, the point is
called a background point.
• depending on whether the gray level of that pixel is greater or less than the
value of T.
Aug 6, 2025 118
Segmentation using Threshold
• 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.
• The following algorithm can be used to obtain T automatically:
G2 .
T = 1/2 (μ1 + μ2 )