DIP Module II
DIP Module II
Image A Image B
Structuring
Oct 14, 2013 element Erosion
DILATION
Dilation is an operation that grows or thickens
objects in a binary image.
The specific manner of this thickening is controlled
by the shape of structuring element.
Dilation combines two sets using vector addition
(a1, a2) + (b1, b2) = (a1 + b1, a2 + b2)
Let,
A = {(1,0), (1,1), (1,2), (2,2), (0,3), (0,4)}
B = {(0,0), (1,0)}
Image B
Image A
Oct 14, 2013
Structuring element Dilation
Dilation
(Another way of defining it)
SE
Reflected SE
Oct 14, 2013 Image A Dilation
DILATION & EROSION ARE DUALS OF EACH OTHER WRT
SET COMPLEMENTATION & REFLECTION
Proof:
Thus,
Remember???
Opening
Generally smoothes the contours of an object
Breaks narrow isthmuses
Eliminates thin protrusions
It is less destructive than the Erosion
GEOMETRICAL INTERPRETATION OF OPENING
The opening of A by B is the union of all the translations of B so
that B fits entirely in A.
Closing
Also tends to smooth sections of the contours
Generally fuses narrow breaks & long thin gulfs
Eliminates small holes & fills gaps in the contour
GEOMETRIC INTERPRETATION OF CLOSING
a) A ∘ B is a subset of A. a) A is a subset of A B.
b) If C is a subset of D, then b) If C is a subset of D, then
C ∘ B is a subset of C B is a subset of
D ∘ B. D B.
c) (A ∘ B) ∘ B = A ∘ B. c) (A B) B = A B.
What will be the result of
i. Erosion
ii. Dilation
iii. Opening
iv. Closing
THE HIT-OR-MISS TRANSFORM (HMT)
♦ HMT is a basic tool for shape detection.
♦ Let I be a binary image composed of
foreground (A) and background pixels,
respectively.
♦ HMT utilizes two structuring elements:
B1 for detecting shapes in the
foreground
B2 for detecting shapes in the
background
B1 = [1 1 1]
1 1 1 1
Eroding the image with a 1 × 3 1 1 1 1 1
mask that corresponds to the shape SE B1 1 1 1
of the object
all objects that are smaller A
than the target object are
removed
1 1
But all objects that are larger
than the mask, i. e., where the
shifted mask is a subset of the 1
object are retained
A ⊖ B1
We need a second operation to 1 1 1 1 1 1 1 1 1
1 1 1 1 1
remove all objects larger than the
1 0 0 0 1 1 0 0 0 0 1 1 1 1
target object.
Can be done by analyzing the 1 1 1 1 1 1 1 1 1 1 1 0 0 1
background of the original SE B2 1 1 0 0 0 1 1 1 1
binary image. 1 1 1 1 1 1 1 1 1
Use as a second step an
AC
erosion of the background with 0 0 0 0 0 0 0 0 0
a 3 × 5 mask B2 in which all
coefficients are zero except for 0 0 0 0 0 0 0 0 0
the pixels in the background, 0 0 0 0 0 0 0 0 0
surrounding the object. 0 0 0 1 0 0 0 0 0
This is a negative mask for the 0 0 0 0 0 0 0 0 0
object
AC ⊖ B2
0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0
A ⊖ B1 AC ⊖ B2
1 1 1 1
1 1
1 A B 1 1 1
As the hit and miss masks of the hit-miss 0 0 0 0 0
operator are disjunct, they can be combined into 0 1 1 1 0
one mask using a hit (1), miss (0), and don’t care 0 0 0 0 0
(x) notation.
Set A
All non-boundary points are labelled 0.
Arbitrarily select a point p, inside the p
boundary and assign it value 1
The objective is to fill the entire region
with 1s.
The region is filled with 1s by the
following procedure.
Xk = (Xk-1 B) ∩ Ac for k = 1, 2, …
where X0 = p
Set A
p origin
Structuring element B
Set A Set Ac
origin
Structuring element B
X0
∩
Oct 14, 2013 Set Ac
The algorithm terminates at iteration step k if Xk = Xk-1.
The set union of Xk and A contains the filled set & its
boundary.
The dilation process would fill the entire area if left unchecked.
The intersection with Ac at each step limits the result to inside the region
of interest.
EXTRACTION OF CONNECTED
COMPONENTS
Extraction of connected components
Structuring
in a binary image is central to many X element B
automated image analysis applications
Let A be a set and Y be a connected
component in it.
Point p of Y is known.
The following iterative expression p
yields all the elements of Y.
Y
X0 = p
Set A
a) Structuring element. p
1 x x 1 1 1 x x 1 x x x
1 0 x x 0 x x 0 1 x 0 x
1 x x x x x x x 1 1 1 1
B1 B2 B3 B4
Following equations are iteratively applied
+1 +1
4
CA Di
i 1
Oct 14, 2013
Oct 14, 2013
1 x x
1 0 x
1 x x
B1
x 0 x
x x x
B2
x 0 1
x x 1
B3
x 0 x
1 1 1
B4
The structuring elements used for thickening have the same form as those for
thinning, but with all 1’s and 0’s interchanged.
A separate algorithm is rarely used for thickening
To thicken A
Let C = Ac
Thin C
Take Cc
Oct 14, 2013
54
IMAGE SEGMENTATION
Segmentation divides an image into its
constituent regions or objects.
Segmentation of non trivial images is
one of the difficult task in image
processing. Still under research.
Segmentation accuracy determines the
eventual success or failure of
computerized analysis procedure.
Example Application: Automated
inspection of electronic assemblies.
(mother boards)
Nov 11, 2013
REGION
Let v be the spatial domain on which the image is defined. Image
segmentation divides v into n regions, Ri (i = 1 to n) such that
indicates that the segmentation must be complete, in the sense
that every pixel must be in a region.
requires that points in a region be
connected in some predefined sense
deals with the(e.g.,
properties
thethe thatmust
points must
regions be8-connected).
be
must satisfied
be disjointby the
pixels in a segmented region - for example, Q (Ri ) =
TRUE if all pixels in Riindicates
have thethat
sametwo
intensity.
adjacent
regions Ri and Rj must be different
in the sense of predicate Q
POINT, LINE AND EDGE DETECTION
♦ Point
a foreground (background) pixel surrounded by background (foreground)
pixels
♦ Line
a (typically) thin edge segment in which the intensity of the background on
either side of the line is either much higher or much lower than the
intensity of the line pixels.
♦ Edge
a set of connected edge pixels where edge pixels are pixels at which the
intensity of an image changes abruptly
DETECTION OF ISOLATED POINTS
o Point detection is based on the second derivative, the Laplacian
Line detection kernels. Detection angles are with respect to the axis system in which
positive angles are measured counterclockwise with respect to the (vertical) x-axis.
EDGE MODELS
Frequently used for segmenting images based on abrupt (local) changes in
intensity.
Edge models are classified according to their intensity profiles.
Step edge
Characterized by a transition between two
intensity levels occurring ideally over the
distance of one pixel.
Step edges occur, for example, in images
generated by a computer for use in areas Ideal representation of a step edge
such as solid modeling and animation. & it’s corresponding intensity profile.
In practice, digital images have edges that are blurred and noisy,
blurring due to limitations in the focusing mechanism (e.g., lenses in the case
of optical images)
noise level determined by the electronic components of the imaging system.
Ramp
The slope of the ramp is inversely
proportional to the degree to which the
edge is blurred.
No single “edge point” along the profile.
An edge point now is any point contained in
the ramp Ideal representation of a ramp
and it’s corresponding intensity
An edge segment a set of such points that profile.
are connected.
Roof Edge
Roof edges are models of lines through a
region, with the width of the edge being
determined by the thickness and sharpness of
the line.
Arise, for example, in range imaging, when thin
objects (such as pipes) are closer to the
sensor than the background (such as walls). Ideal representation of a roof
The pipes appear brighter . edge and it’s corresponding
Also appear in the digitization of line drawings intensity profile.
& in satellite images, where thin features, such
as roads, can be modeled by this type of edge.
The First derivative
– is positive at the onset of the ramp
and at points on the ramp,
– it is zero in areas of constant
intensity.
– the magnitude of the first derivative
can be used to detect the presence
of an edge at a point in an image
a) Two regions of constant intensity separated
by an ideal ramp edge.
b) Detail near the edge, showing a horizontal
intensity profile & its first & second
derivatives.
The Second derivative
– is positive at the beginning &
negative at the end of the ramp
– zero at points on the ramp & at
points of constant intensity.
– The intersection between the zero
intensity axis and a line extending
between the extrema of the second
a) Two regions of constant intensity separated derivative marks a point called the
by an ideal ramp edge. zero crossing of the second
b) Detail near the edge, showing a horizontal derivative.
intensity profile & its first & second
derivatives.
Properties of Second Derivative
1. The sign of the second derivative can be used to determine whether an
edge pixel lies on the dark or light side of an edge.
2. it produces two values for every edge in an image
3. its zero crossings can be used for locating the centers of thick edges
4. It is very sensitive to noise
Three steps for edge detection are:
1. Image smoothing
for noise reduction.
2. Detection of edge points
a local operation that extracts from an image all points that are potential
First column: 8-bit images with
edge-point candidates.
values in the range [0,255], and
3. Edge
intensity localization
profiles of a ramp edge
corrupted by Gaussian noise.
to select from the candidate points only the points that are members of
Second column: First-derivative
imagesthe
andset of points
intensity comprising an edge.
profiles.
Third column: Second-derivative
images and intensity profiles.
HOW CAN YOU TELL THAT A PIXEL IS ON AN
EDGE?
Edge Orientation
∂f / ∂y = 2
M(x, y) = 22
= tan-1(gy / gx)
-45°
which is the same as
135° measured in
the positive
(counterclockwise)
direction with respect to
the x-axis
Roberts Operator (Roberts [1965])
Used when diagonal edge direction is of interest.
The Roberts cross-gradient operators use 2-D
kernels with a diagonal preference.
Kernels of size 2 × 2 are simple conceptually, but
they are not as useful for computing edge
direction as compared with kernels that are
symmetric about their centers.
The smallest such kernel is of size 3 × 3. These
kernels take into account the nature of the data
on opposite sides of the center point, and thus
carry more information regarding the direction
of an edge.
Prewitt Operators (Prewitt [1970])
d ( x, y ) d12 ( x, y ) d 22 ( x, y )
Use to estimate the
gradient magnitude, and use T = 5 as the threshold for edge detection
Nov 11, 2013 75
0 1 0 0 0 0 0 0
-1 0 0 0 0 -7 -1 0
0 0 0 0 0 1 0 0 edge map
2 0 0 0 -7 0 0 0
d1 0 0 0 0 0 0 0 0
0 1 0 0 0 -7 0 0 0 -2
1 1 1 0 0 0 7 7 0 0 0 0 0 0 1 1 0
0
0 0 0 0 0 0 2 0
1 1 0 0 0 9.2 1 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0
0 0 0 0 7 7.1 1 0 0 0 0 0 1 1 0 0
original 2 0 0 0 9.9 0 0 0 0 0 0 0 1 0 0 0
image 1 0 0 0 0 7 7 0
2 0 0 7 7 0 0 0 0 0 0 1 1 0 0 0
0 0 0 9.9 0 0 2 2 0 0 0 1 0 0 0 0
0 -1 0 0 0 6 0 0
0 0 7 7 0 0 2 2 0 0 1 1 0 0 0 0
0 0 0 0 7 7 1 0
0 0 0 0 7 0 0 0 0 7 7 0 0 1 1 0 0 1 1 0 0 0 0 0
1 0
d
0 21
-2 0 0 7 7 0 0 0
0 0 0 7 0 0 -2 0
thresholding
0 0 7 7 0 0 0 2
0 7 7 0 0 1 0 0
T=5
Nov 11, 2013
d 2 ( x, y ) Note: 8x8 images (because of boundary problems)
SIMPLE EDGE
DETECTION
USING
GRADIENTS
…
THE CANNY EDGE DETECTOR
Algorithm more Performance
complex superior
thresholding
edge map
ALGORITHM
Step 1
Let f (x, y) denote the input image and G(x, y) denote
the Gaussian function:
Experimental evidence (Canny [1986]) suggests that the ratio of the high
to low threshold should be in the range of 2:1 to 3:1.
Edge pixels stronger than TH are marked as strong; edge
pixels weaker than TL are suppressed and edge pixels between
the two thresholds are marked as weak.
Thresholding of edges. In the second image strong edges are
white, while weak edges are grey. Edges with a strength
below both thresholds are suppressed.
Strong edges are interpreted as “certain edges” and can immediately be
included in the final edge image.
Weak edges are included if and only if they are connected to strong edges.
The logic is that noise and other small variations are unlikely to result in
a strong edge. Thus strong edges will (almost) only be due to true edges
in the original image.
The weak edges can either be due to true edges or noise/color
variations. The latter type will probably be distributed independently of
edges on the entire image, and thus only a small amount will be located
adjacent to strong edges.
Weak edges due to true edges are much more likely to be connected
directly to strong edges.
Edge tracking and final output. The middle image shows strong edges in white, weak
edges connected to strong edges in blue, and other weak edges in red
An edge element is deemed present at (x,y) if f’(x, y) exceeds a
predefined threshold
if P[m][
][cc] = M, then M points lie on the line y = m x + c
Find the equation for the edge for the following edge
points
• (2,2) c = -2m + 2
• (4,7) c = -4m + 7
• (5,5) c = -5m + 5
• (6,2) c = -6m + 2
• (6,6) c = -6m + 6
p = x cos θ + y sinθ
sinθ
Aug 01, 2016 101
ALGORITHM
1. Quantize the parameter space (p, θ)
P[pmin, . . . , pmax][θmin, . . . ,θmax]
2. For each edge point (x, y)
For(θ = θmin; θ ≤ θmax; θ ++) {
p = x cos(θ) + y sin(θ) ; /* round off if needed *
(P[p][θ])++; /* voting */
}
3. Find local maxima in P[p][θ]
y
6
5
Use
4 Hough Transform to form the
3
2
main edge.
1 Work with polar coordinates
0
0 1 2 3 4 5 6 x
p = x cos θ + y sinθ
Edgels – (0,5), (1,4), (3,2), (3,3), (5,0)
Aug 01, 2016 103
In the given question, the curve corresponding to the point (3,3)
does not intersect at the common point (3.5, 45), where the other
curves meet.
So
2. Check for 8 neighbours of the newly added pixels. If they satisfy the
homogeneity criteria, add them to the region
5. All pixels in the current region are marked with a unique label.
9 6 6 6 7 7 6 6
Find the regions for 6 7 6 7 5 5 4 7
the given seeds. 6 6 4 4 3 2 5 6
Threshold value = 3
5 4 5 4 2 3 4 6
1 3 2 3 3 2 4 7
0 0 1 0 2 2 5 6
1 1 0 1 0 3 4 4
1 0 1 0 2 3 5 6
REGION SPLITTING (TOP DOWN APPROACH)
REGION MERGING (BOTTOM UP METHOD)
Start from pixel level. Consider each of them as a homogeneous region.
Repeat the operation recursively until there are no more regions that can
be merged.
5 6 6 6 7 7 6 6 Find the regions based
6 7 6 7 5 5 4 7 on
6 6 4 4 3 2 5 6
5 4 5 4 2 3 4 6 1. Region splitting
1 3 2 3 3 2 4 7 technique
0 0 1 0 2 2 5 6
1 1 0 1 0 3 4 4 2. Region merging
1 0 1 0 2 3 5 6 technique
1101101030332330322212
3
PROBLEMS WITH CHAIN CODES
the resulting chain of codes tends To use boundary representation
to be quite long in object recognition, we need to
any small disturbances along the achieve invariance to starting
boundary due to noise or imperfect point and orientation
segmentation cause changes in the Normalized codes
code that may not be related to the
shape of the boundary Differential codes
Dependent on the starting point
Dependent on the orientation
NORMALIZATION STRATEGY
TO OVERCOME THE STARTING POINT PROBLEM
33001122 00112233
30011223 Sort 01122330
00112233 rows 11223300
01122330 12233001
11223300 22330011
12233001 23300112
22330011 30011223
23300112 33001122
33001212 33010122
01011311
01011311 01131101
SHAPE NUMBERS
Order 8