Lab2 13 OpenCV2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

430.211.

001: Programming Methodology

Lecture 13: Open CV

Bohyung Han
bhhan@snu.ac.kr
Department of Electrical and Computer Engineering
Content
● Basic
● Canny Edge Detector
● Histogram Stretching
● Histogram Equalization
● Assignment

2
Content
● Basic
● Canny Edge Detector
● Histogram Stretching
● Histogram Equalization
● Assignment

3
Basic
● Write Code on main.cpp

4
Basic
● Write Code on main.cpp

5
Basic
● Write Code on main.cpp

6
Basic
● Write Code on main.cpp

7
Basic
● Write Code on main.cpp

8
Basic
● Write Code on main.cpp

9
Basic
● Write Code on main.cpp

10
Basic
● Write Code on main.cpp

11
Basic
● Write Code on main.cpp

12
OpenCV Setup with Cmake on VSCode
● Write Code on main.cpp

13
Basic
● Write Code on main.cpp

14
Basic
● Write Code on main.cpp

15
Content
● Basic
● Canny Edge Detector
● Histogram Stretching
● Histogram Equalization
● Assignment

16
Canny Edge Detector
● One of the most popular edge detection algorithms

17
Canny Edge Detector
1. Soothing image with Gaussian filter

𝑺(𝑖, 𝑗) = 𝑮(𝑖, 𝑗; 𝜎) ∗ 𝒇(𝑖, 𝑗)

2. First-difference approximation

𝑷(𝑖, 𝑗) ≊ (𝑺(𝑖, 𝑗+1) - 𝑺(𝑖, 𝑗) + 𝑺(𝑖+1, 𝑗+1) - 𝑺(𝑖+1, 𝑗)) / 2


𝑸(𝑖, 𝑗) ≊ (𝑺(𝑖, 𝑗) - 𝑺(𝑖+1, 𝑗) + 𝑺(𝑖, 𝑗+1) - 𝑺(𝑖+1, 𝑗+1)) / 2

18
Canny Edge Detector
3. Compute gradient magnitude and orientation

magnitude : 𝑴(𝑖, 𝑗) = sqrt(𝑷(𝑖, 𝑗)^2 + 𝑸(𝑖, 𝑗)^2)

angle : 𝜃(𝑖, 𝑗) = arctan(𝑸(𝑖, 𝑗) / 𝑷(𝑖, 𝑗))

4. Nonmaximum suppression (for edge thinning)


- Delete surrounding local minima

19
Canny Edge Detector
5. Thresholding

20
Canny Edge Detector
● Write Code on main.cpp

Gaussian blur

blur(
input image,
output image,
kernel size)

21
Canny Edge Detector
● Write Code on main.cpp

Canny(
input image,
output image,
low threshold,
high threshold,
aperture size = 3,
L2 gradient = false)

22
Canny Edge Detector
● Write Code on main.cpp

cvtColor(
source image,
target image,
option)

23
Canny Edge Detector
● Write Code on main.cpp

createTrackbar(
trackbar name,
window name,
value,
max value,
callback function)

*callback function :
Call when the value of
the trackbar changes

24
Canny Edge Detector
● Write Code on main.cpp

25
Content
● Basic
● Canny Edge Detector
● Histogram Stretching
● Histogram Equalization
● Assignment

26
Histogram Stretching
● Conventional image processing technique
● Straight-forward method of contrast enhancement

27
Histogram Stretching
● Write Code on main.cpp

28
Histogram Stretching 1
● Write Code on main.cpp

29
Histogram Stretching 2
● Write Code on main.cpp

30
Histogram Stretching 3
● Write Code on main.cpp

31
Content
● Basic
● Canny Edge Detector
● Histogram Stretching
● Histogram Equalization
● Assignment

32
Histogram Equalization
● Conventional image processing technique for contrast enhancement
● Pixel values becomes an uniform distribution

● Img_Eq = cdf(Img)

33
Histogram Equalization 1
● Write Code on main.cpp temp_hist used in
Histogram Stretching Method3

34
Histogram Equalization 1
● Write Code on main.cpp

35
Histogram Equalization 2
● Write Code on main.cpp

36

You might also like