Machine Learning Course Shashi Lecture 05
Machine Learning Course Shashi Lecture 05
Shashikant Dugad,
IISER Mohali
● Usefulness of associativity
○ Often apply several filters one after another: (((a ★ b1) ★ b2) ★ b3)
○ This is equivalent to applying one filter: a * (b1 ★ b2 ★ b3)
● The kernel size, stride value can substantially reduce the size of output im the
output size and computational efficiency of the network, influencing feature
extraction and spatial dimensions of image.
Shashikant R Dugad, IISER Mohali 4
Movement of Filter
Stride = 1
Stride = 2
𝑵𝒊𝒏
𝒓𝒐𝒘 ' 𝟐 𝑿 𝑷 , 𝑫𝒓𝒐𝒘 𝑿 (𝑲𝒓𝒐𝒘 ,𝟏) ,𝟏
𝑵𝒐𝒖𝒕
𝒓𝒐𝒘 = 𝑺𝒓𝒐𝒘
+1
𝑴𝒊𝒏
𝒄𝒐𝒍 ' 𝟐 𝑿 𝑷 , 𝑫𝒄𝒐𝒍 𝑿 (𝑲𝒄𝒐𝒍 ,𝟏) ,𝟏
𝑴𝒐𝒖𝒕
𝒄𝒐𝒍 = 𝑺𝒄𝒐𝒍
+1
padding=1, stride=2
● However, step and line edges are rare in real images due to the low-frequency components
or the smoothing of the image.
● Step edges become ramp edges and line edges become roof edges
Step Ramp
Line
Ramp
Line
Ramp Roof
Line
Line Roof
● An edge
Roofis
associated with the maxima in the first derivative (gradient) ofedge
Figure 5.1: One-dimensional intensity
profiles. in
local region of an image
Figure 5.1: One-dimensional edge profiles.
● The gradient
Roof is the two-dimensional equivalent of the first derivative and is defined as
Figure 5.1: One-dimensional edge profiles. It is also possible for an edge to have both step and line characteristi
the vector For example, a surface that changes orientation from one flat surface
anotherIt is will
alsoproduce
possible afor step
an edge;
edge tobuthave
if the surface
both has line
step and a specular compon
characteristics.
Figure 5.1: One-dimensional edge profiles. ofFor
reflectance
example, and 𝝏𝒇
a if the
surface surface
that corner
changes is rounded,
orientation there
from can
one be
flata highlight
surface to d
It is also possible for an edge to have both step and line characteristics.
For example, a surface that changes orientation from one flat
𝑮the
toanother specular
𝒙surface to 𝝏𝒙
component
will produce as the
a step edge; butsurface orientation
if the surface of the rounded
has a specular component cor
𝑮(𝒇 𝒙, 𝒚) = to component
another will produce a step edge; but if the surface has a specular
passes =
of reflectance
the and ifangle
precise
the specular
the surface
component
for corner is reflection.
specular
as thea surface
rounded, there
The
orientation
can be aprofile
edge highlight
of the rounded line
due
genera
cornered
by such a situation looks like step edge with a superimposed
It is also possible for an edge to have both step and line characteristics.
of reflectance and if the surface corner is rounded, there can be aThere 𝑮surface
highlight
passes
𝒚 are thedue 𝝏𝒇
precise angle for specularwithreflection.
changes The edge profile generated
For example,
speculara component
surface that aschanges orientation from ofone
the flat toalso edges associated in the first derivative of
to the
another willprecise
produce a stepfor
the surface
edge; but
orientation
if reflection.
the surface The
has aedge
specular
rounded
by such corner
a
image intensity.
component 𝝏𝒚For example, mutual reflection from the sides of a10conc
situation looks like a step edge with a superimposed line edge.
Shashikant
passes the R Dugad,
angle IISER Mohali
specular There
profile are
generated
corner generate also edges associated
roof edges. Edgeswithare
changes in theimage
important first derivative of theth
features since
of reflectance and if the surface corner is rounded, there can be a highlight due
image intensity. For example, mutual reflection from the sides of a concave
Gradient
● The vector G[f(x, y)] points in the direction of the maximum rate of
increase of the function f(x, y)
11
Shashikant R Dugad, IISER Mohali
Gradient for digital image
● Gradient for a digital image can be defined as,
𝑮𝒙 𝒊, 𝒋 ≅ 𝒇 𝒊, 𝒋 + 𝟏 − 𝒇 𝒊, 𝒋 . 𝑮𝒚 𝒊, 𝒋 ≅ 𝒇 𝒊 + 𝟏, 𝒋 − 𝒇 𝒊, 𝒋
● These can be implemented with simple convolution masks as shown
below:
+1
Gx = -1 +1 Gy =
-1
12
Shashikant R Dugad, IISER Mohali
Edge Detection Operators
1 01 0 0 -10 -1
● Gx = Gy =
0 -10 -1 1 01 0
● The Roberts operator is NOT located at the desired point [i,j].
● In order to have an edge operation at fixed point [i,j] in both the directions, we
should have a mask of 3x3 size
● Sobel operator is the magnitude of the gradient computed by,
𝑴= 𝑺𝟐𝒙 + 𝑺𝟐𝒚
(b)
(a) (b)
(d) (e)
(c) (d)
f'- - ~
~CJ~
\
'
,.
":~
\'.
(f) (g)
(e) (f)
Figure 5.6: A comparisonof various edge detectors on a noisy image. (a)
Figure 5.7: A comparison of various edge detectors on a noisy image without Noisy image. (b) Filtered image. (c) Simple gradient using 1 x 2 and 2 x 1
filtering. (a) Noisy image. (b) Simple gradient using 1 x 2 and 2 x 1 masks, masks, T = 32. (d) Gradient using 2 x 2 masks, T = 64. (e) Roberts
T = 64. (c) Gradient using 2 x 2 masks, T = 128. (d) Roberts cross operator, cross operator, T = 64. (f) Sobel operator, T = 225. (g) Prewitt operator,
T = 64. (e) Sobel operator, T = 225. (f) Prewitt operator, T = 225. T = 225.
https://cse.usf.edu/~r1k/MachineVisionBook/MachineVision.files/
Shashikant R Dugad, IISER Mohali 16
Edge Detection with Second Derivative Operators
● A single derivate edge operators with a threshold provides too many edge points
depending on noise in the image
● A better approach would be to find only the points that have local maxima in
gradient values and consider them a edge points.
○ This means that at edge
CHAPTER points,
5. EDGE there will be a peak in the first derivative and,
DETECTION
equivalently, there will be a zero crossing in the second derivative.
𝝏𝒇(𝒙, 𝒚)
𝑮𝒙 = = 𝒇 𝒊, 𝒋 + 𝟏 − 𝒇 𝒊, 𝒋
𝝏𝒙
𝝏𝟐 𝒇 𝒙, 𝒚 𝝏𝑮𝒙 𝝏𝒇 𝒊, 𝒋 + 𝟏 𝝏𝒇 𝒊, 𝒋
∴ = = − = 𝒇 𝒊, 𝒋 + 𝟐 − 𝒇 𝒊, 𝒋 + 𝟏 − 𝒇 𝒊, 𝒋 + 𝟏 + 𝒇 𝒊, 𝒋
𝝏𝒙𝟐 𝝏𝒙 𝝏𝒙 𝒅𝒙
𝝏𝟐 𝒇 𝒙, 𝒚
= 𝒇 𝒊, 𝒋 + 𝟐 − 𝟐𝒇 𝒊, 𝒋 + 𝟏 + 𝒇(𝒊, 𝒋)
𝝏𝒙𝟐
● However, this approximation is centered about the pixel [i,j + 1]. Therefore, by
replacing j with j - 1,
𝝏𝟐 𝒇 𝒙, 𝒚 𝝏𝟐 𝒇 𝒙, 𝒚
= 𝒇 𝒊, 𝒋 + 𝟏 − 𝟐𝒇 𝒊, 𝒋 + 𝒇 𝒊, 𝒋 − 𝟏 . = 𝒇 𝒊 + 𝟏, 𝒋 − 𝟐𝒇 𝒊, 𝒋 + 𝒇(𝒊 − 𝟏, 𝒋)
𝝏𝒙𝟐 𝝏𝒚𝟐
● By combining these two equations into a single operator, the following mask
can be used to approximate the Laplacian:
0 0 0 0 1 0 0 0 0 00 11 00
∇2 =1 ∇2-2x + 1∇2y = 0 -2 0 + 1 -2 1 = 01 -2-4 01
0 0 0 0 1 0 0 0 0 00 11 00
● The output of the LoG operator, h(x, y), is obtained by the convolution
operation
0.3
0 0 -1 0 0
0.2
0 -1 -2 -1 0
16 -2 -1
0.1
0.1
-1 -2
.().1
10
0 -1 -2 -1 10
0
0 0 -1 0 0
-4>._\0 -8 -6 ... -2 10
● The slope of the zero crossing depends on the contrast or sharpness of the
change in image intensity across the edge.
● A larger σ results in better noise filtering but may lose important edge
information, which may affect the performance of an edge detector. If a
small filter is used, there is likely to be more noise due to insufficient
averaging.
● The gradient may have greater sensitivity to the presence of edges, but it
has higher sensitivity to the noise.
● The linear operator that provides the best compromise between noise
immunity and localization, is the first derivative of a Gaussian.