Week7 - Edge, Line, Texture
Week7 - Edge, Line, Texture
Image Processing
INT3404 1/ INT3404E 21
Giảng viên: TS. Nguyễn Thị Ngọc Diệp
Email: [email protected]
Schedule
Tuần Nội dung Yêu cầu đối với sinh viên (ngoài việc đọc tài liệu tham khảo)
1
Giới thiệu môn học Cài đặt môi trường: Python 3, OpenCV 3, Numpy, Jupyter Notebook
1
15/03/2023
Edge detection
2
15/03/2023
a b
c
FIGURE 10.2
(a) Image.
(b) Horizontal
- An edge = a significant local change
intensity profile
that includes the
in the image intensity isolated point
indicated by the
arrow.
(c) Subsampled
profile; the dashes
were added
for clarity. The
numbers in the
boxes are the
intensity values
of the dots shown
in the profile. The
derivatives were 7 Isolated point
obtained using 6
Intensity
Image credit: Gonzalez et.al., Fig. 10.2 First derivative !1!1!1!1!1 0 0 6 !6 0 0 0 1 2 !2!1 0 0 0 7 0 0 0
5
in the ramp spans four pixels, the noise point is a single pixel, the line is three pixels
thick, and the transition of the step edge takes place between adjacent pixels. The
number of intensity levels was limited to eight for simplicity.
Consider the properties of the first and second derivatives as we traverse the
profile from left to right. Initially, the first-order derivative is nonzero at the onset
and along the entire intensity ramp, while the second-order derivative is nonzero
only at the onset and end of the ramp. Because the edges of digital images resemble
this type of transition, we conclude that first-order derivatives produce “thick” edges,
and second-order derivatives much thinner ones. Next we encounter the isolated
Image gradient
noise point. Here, the magnitude of the response at the point is much stronger for
the second- than for the first-order derivative. This is not unexpected, because a
second-order derivative is much more aggressive than a first-order derivative in
enhancing sharp changes. Thus, we can expect second-order derivatives to enhance
fine detail (including noise) much more than first-order derivatives. The line in this
example is rather thin, so it too is fine detail, and we see again that the second deriva-
tive has a larger magnitude. Finally, note in both the ramp and step edges that the
3
15/03/2023
Gradient
• Gradient of a function indicates how strong the function
increases.
• For 1-dimension function: f ( x) = x 2
¶f ( x)
Grad ( x) = = 2x
¶ ( x)
• Grad(2)=4 indicates the the increasing direction of the function is
to the right.
• Grad(-1)=-2 indicates the increasing direction of the function is to
the left.
4
15/03/2023
¶f ( x, y) ¶f ( x, y)
= f ( x + 1, y) - f ( x, y), = f ( x, y + 1) - f ( x, y)
¶x ¶y
10
5
15/03/2023
Gradient of 2D image
convolution
11
Gradient
• The magnitude of gradient indicates the strong of edges:
2 2
æ ¶f ( x, y ) ö æ ¶f ( x, y ) ö
Grad ( x, y ) = ç ÷ +ç ÷
è ¶y ø è ¶x ø
• Gradient computation procedure:
• Calculate column gradient
• Calculate row gradient
• Calculate final gradient by the above function
12
6
15/03/2023
a
b c z1 z2 z3
z7 z8 z9 !1 !1 !1 !1 0 1
A 3x3
!1 region
0 0of an
!1image
0 0 0 !1 0 1
1 1 1 !1 0 1
0 1 1 0
Prewitt
Roberts
!1 !2 !1 !1 0 1
!1 !1 !1 !1 0 1
0 0 0 !2 0 2
0 0 0 !1 0 1
1 2 1 !1 0 1
1 1 1 !1 0 1 Sobel
Prewitt
!1 !2 !1 !1 0 1 ∂f
gx = = (z7 + 2z8 + z9 ) − (z1 + 2z2 + z3 ) (10-24)
∂x
0 0 0 !2 0 2
and
∂f
1 2 1 !1 0 1 gy = = (z3 + 2z6 + z9 ) − (z1 + 2z4 + z7 ) (10-25)
13 ∂y
Sobel It can be demonstrated (see Problem 10.12) that using a 2 in the center location pro-
vides image smoothing. Figures 10.14(f) and (g) show the kernels used to implement
Eqs. (10-24) and (10-25). These kernels are called the Sobel operators (Sobel [1970]).
The Prewitt kernels are simpler to implement than the Sobel kernels, but the
∂f
gx = = (z7 + 2z8 + z9 ) − (z1 + 2z2slight
+ z3 ) computational(10-24)
difference between them typically is not an issue. The fact
∂x that the Sobel kernels have better noise-suppression (smoothing) characteristics
makes them preferable because, as mentioned earlier in the discussion of Fig. 10.11,
nd
noise suppression is an important issue when dealing with derivatives. Note that the
∂f
gy = = (z3 + 2z6 + z9 ) − (z1 + 2z4 + z7 ) (10-25)
∂y
é0 0 0 ù é0 -1 0 ù
ê0 1 -1ú ê0 1 0 ú
ê ú
6/16/2017 2:12:51 PM ê ú
êë0 0 0 úû êë0 0 0úû
14
7
15/03/2023
Row
edges
15
Robert mask
• Roberts masks calculate gradient from two diagonals
Column Row
é0 0 -1ù é -1 0ù
ê0 1 0 ú ê 0 1 0ú
ê ú ê ú
êë0 0 0 úû êë 0 0 0 úû
16
8
15/03/2023
Row
edges
17
Prewitt mask
Column Row
é1 0 -1ù é -1 -1 -1ù
1ê 1ê
ê 1 0 -1úú ê 0 0 0 úú
3 3
êë1 0 -1úû êë 1 1 1 úû
18
9
15/03/2023
Prewitt mask
Row
edges
Original Image Final edges
Column
edges
19
Sobel mask
Column Row
é1 0 -1ù é -1 -2 -1ù
1ê 1ê
ê 2 0 -2 úú ê 0 0 0 úú
4 4
êë1 0 -1úû êë 1 2 1 úû
20
10
15/03/2023
Row
21
Laplace gradient
• Laplace edge in a continuous domain
æ ¶ 2 f ( x, y ) ¶ 2 f ( x, y ) ö
G ( x, y ) = - ç + ÷
è ¶x ¶y 2 ø
2
= f ( x, y ) * H ( x, y )
22
11
15/03/2023
Laplace mask
é0 0 0 ù é0 -1 0 ù
H = êê -1 2 -1úú + êê0 2 0 úú
êë 0 0 0 úû êë0 -1 0 úû
é0 -1 0ù
= êê -1 4 -1úú
êë 0 -1 0 úû
23
24
12
15/03/2023
25
26
13
15/03/2023
Gradient comparison
Pixel difference Robert Prewitt
Sobel Laplace
27
28
14
15/03/2023
31
32
15
15/03/2023
3. Non-maximum suppression
4. Thresholding
https://towardsdatascience.com/canny-edge-detection-step-by-step-in-python-computer-vision-b49c3a2d8123
34
35
16
15/03/2023
Line detection
Hough transform
36
37
17
15/03/2023
38
39
18
15/03/2023
Line planes
y = a’x + b’
41
42
19
15/03/2023
43
44
20
15/03/2023
45
46
21
15/03/2023
Canny edges
original
47
48
22
15/03/2023
Everything appears to be “noise”, or random edge points, but we still see some peaks in the vote space
49
Texture analysis
50
23
15/03/2023
What is texture?
51
Aspects of texture
• Size/granularity (sand versus pebbles
versus boulders)
• Directionality/Orientation
• Random or regular (stucco versus bricks)
52
24
15/03/2023
53
54
25
15/03/2023
55
Example
Original Image Frei-Chen Thresholded
Edge Image Edge Image
56
26
15/03/2023
57
LBP example
Color Image -> Grayscale Image -> LBP Mask -> Normalized LBP Histogram
58
27
15/03/2023
59
GLCM example
60
28