การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image...

51
การแบ่งข้อมูลภาพ Image Segmentation 1 เซ็กเม็นเตชัน(Segmentation) เป็นการแบ่ง ข้อมูลภาพออกเป็นส่วนย่อยๆ ที่แต่ละส่วนจะมีพื้นทีต่อกันไป แต่ละส่วนจะเป็นพื้นที่ซึ่งอาจจะแท่นวัตถุทีอยู ่ในภาพ เซ็กเม็นเตชันจะเสร็จเมื่อวัตถุที่ต้องการ ถูก แบ่งออกได้สมบูรณ์ ผลลัพธ์ที่ได้จากการเซ็กเม็นต์จะ เป็นตัวชี้วัดความสาเร็จในขั้นตอนการวิเคราะห์ภาพ ด้วยคอมพิวเตอร์

Transcript of การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image...

Page 1: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

การแบงขอมลภาพ

Image Segmentation

1

เซกเมนเตชน(Segmentation) เปนการแบงขอมลภาพออกเปนสวนยอยๆ ทแตละสวนจะมพนทตอกนไป แตละสวนจะเปนพนทซงอาจจะแทนวตถทอยในภาพ เซกเมนเตชนจะเสรจเมอวตถทตองการ ถกแบงออกไดสมบรณ ผลลพธทไดจากการเซกเมนตจะเปนตวชวดความส าเรจในขนตอนการวเคราะหภาพดวยคอมพวเตอร

Page 2: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

2

Introduction • What is image segmentation?

– Technically speaking, image segmentation refers to the decomposition of a scene into different components (thus to facilitate the task at higher levels such as object detection and recognition)

– Scientifically speaking, segmentation is a hypothetical middle-level vision task performed by neurons between low-level and high-level cortical areas

• There is no ground truth to a segmentation task (an example is given in the next slide)

Page 3: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

3

Dilemma

input result 1 result 2

What do we mean by “DIFFERENT” objects?

Another example: when we look at trees at a close distance, we consider each of them as a different object; but as we look at trees far away, they merge into one coherent object (woods)

Page 4: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

4

Overview of Segmentation Techniques

Texture images

Document images

Medical images

Biometric images

Range images Texture-based

Edge-based

Color-based

Disparity-based

Motion-based

Page 5: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

5

Edge-based Techniques

Edge

detection

Segmentation

by boundary

detection

Classification

and analysis

Page 6: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

6

Region-Filling

Page 7: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

7

Color-Based Techniques

• Color representations

– Device dependent: RGB (displaying) or CMYK (printing)

– Device independent: CIE XYZ or CIELAB (L*a*b*)

• There are different specifications of RGB color spaces (e.g., HP/Microsoft vs. Adobe)

Page 8: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

8

Color Space Conversion

Analog TV

Digital TV(MPEG)

Page 9: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

9

Data Clustering via Kmeans

Instead of 2D, kmeans can be applied to 3D color space RGB or L*a*b*

Page 10: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

10

Texture-based Techniques

What is Texture? No one exactly knows. In the visual arts, texture is the perceived surface quality of an artwork.

Page 11: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

11

Disparity-based Techniques

Page 12: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

12

Motion Segmentation

Page 13: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

13

Document Segmentation

• Document images consist of texts, graphics, photos and so on

• Document segmentation is useful for compression, text recognition

• Adobe and Xerox are the major players

Page 14: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

14

Medical Image Segmentation

• Medical image analysis can be used as preliminary screening techniques to help doctors

• Partial Differential Equation (PDE) has been used for segmenting medical images

active contour model (snake)

Page 15: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

15

Range Image Segmentation

range intensity ground truth

Page 16: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

16

Biometric Image Segmentation

• For fingerprint, face and iris images, we also need to segment out the region of interest

• Various cues can be used such as ridge pattern, skin color and pupil shape

• Robust segmentation could be difficult for poor-quality images

Page 17: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

การเซกเมนตภาพในระดบลาง • ขนตอนการเซกเมนตภาพเกรยสเกลจะอาศยหนงในสองคณสมบตพนฐานของคาความเขม นนคอ –ความไมตอเนองและความเปนเนอเดยวกนหรอความเหมอนกน ความไมตอเนองจะถกก าหนดดวยการเปลยนแปลงอยางทนททนใดของคาความเขม เชนขอบ

–สวนความเหมอนกนจะแบงขอมลออกเปนสวนๆโดยแตละสวนจะมเกณฑการวดความเหมอนกนทก าหนดขน

17

Page 18: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

• จะใชลาปลาเชยลวนโดวเพอตรวจหาจด • Laplacian masks have the largest coefficient at the center of the mask while neighbor pixels have an opposite sign. • This mask will give the high response to the object that has the similar shape as the mask such as isolated points.

• Notice that sum of all coefficients of the mask is equal to zero. This is due to the need that the response of the filter must be zero inside a constant intensity area

18

การตรวจหาจด -1 -1

-1

8

-1

-1

-1

-1

-1

-1 0

0

4

-1

-1

0

-1

0

Page 19: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

การตรวจหาขอบ จดและเสน • การตรวจหาความไมตอเนองในภาพระดบสเทาจะไดสวนทเปนขอบ จดและเสน

• การตรวจหาจด

19

การตรวจหาจดอยางงายจะใชตวกรองลาปลาสเมอน าภาพไปคอนโวลชนกบตวกรองกจะไดผลลพธ(รปกลาง) เมอน าไปเทรสโฮลดกจะไดจด (รปขวา)

Location of

porosity

Page 20: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

การตรวจหาเสน • การตรวจหาเสนจากรปจะใชตวกรอง −1 − 1 − 1 2 2 2−1 − 1 − 1

−1 − 1 2−1 2 − 1 2 − 1 − 1

−1 2 − 1−1 2 − 1−1 2 − 1

2 − 1 − 1−1 2 − 1−1 − 1 2

• ทใหหาเสนในแนวนอน 45 องศา แนวตง และ –45องศา เมอน าแตละตวกรองไปตรวจหาเสน

ในแตละแนวกจะไดผลลพธดงรป แนวนอน 45 องศา แนวตง 135องศา

20

Page 21: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

การตรวจหาเสน (ตอ)

21

เมอน าผลลพธของตวกรองทงสทศทางมารวมกน โดยเลอกเฉพาะคาสงสดจากตวกรองทงสทศกจะได

Page 22: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

การตรวจหาเสนดวยการแปลงฮฟ(Hough Transform)

22

• Problem: fit a straight line (or curve) to a set of edge pixels

• Hough transform (1962): generalized template matching technique

• Consider detection of straight lines: 𝑦 = 𝑚𝑥 + 𝑐

Page 23: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Hough transform (cont.)

23

• Subdivide (m,c) plane into discrete “bins,” initialize all bin counts by 0

• Draw a line in the parameter space m,c for each edge pixel x,y and increment bin counts along line.

• Detect peak(s) in (m,c) plane

Page 24: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Hough transform (cont.)

24

Alternative parameterization avoids infinite-slope problem

Similar to Radon transform

Calculation of the Hough transform and its inverse

Page 25: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Hough transform and inverse Hough transform

25

• With the Hough transform with x cos θ + y sin θ = ρ a point (x,y) in the image becomes a sinusoid in the Hough parameter space. • With the inverse Hough transform with x cos θ + y sin θ = ρ a point (ρ,θ) in the Hough parameter space becomes a line in the image.

Page 26: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Discrete implementation and relation to the Radon transform

26

When the loop variables are changed, the Hough transform turns into the Radon transform.

For all (x,y) where f(x,y)!=0 For all (ρ,θ) where x cosθ+y sinθ =ρ H(ρ,θ):= H(ρ,θ) + f(x,y) END

END

The Radon transform are known from computer tomography (CT). It performs line integrals through the object function f(x,y)

For all (r,θ) For all (x,y) where x cosθ+y sinθ =ρ H(ρ,θ):= H(ρ,θ) + f(x,y) END

END

Hough transform

Radon transform

Page 27: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Hough transform Example A

27

Page 28: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Hough transform Example B

28

Page 29: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Hough transform Example C

29

Page 30: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Hough transform example

30

Page 31: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Line detection with the Hough transform

31

a) b) c) d) a) Infrared image of

an airport. b) Thresholded magnitude of the gradient. c) Hough transform

d) Inverse Hough transform of the 3 strongest peeks in c) combined with linking of gaps < 5 pixels. Then overlaid on a).

Page 32: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Circle detection by Hough transform

32

𝑥 − 𝑐12 + 𝑦 − 𝑐2

2 = 𝑐32

ในกรณนเราจะตรวจหาสามตวแปรคอ 𝑐1, 𝑐2และ 𝑐3 ในปรมาตร 𝐴(𝑖, 𝑗, 𝑘) โดยเรมจากใช 𝑐1และ 𝑐2 เพอแกสมการหา 𝑐3 เชนเมอตองการหาจดทเชอมตอกนเปนวงกลม

Page 33: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Hough transform and inverse Hough transform of circles

33

• With the Hough transform with 𝑥 − 𝑐1

2 + 𝑦 − 𝑐22 = 𝑐3

2 a point (𝑐1, 𝑐2) in the image becomes a circle in the Hough parameter space. • With the inverse Hough transform with

𝑥 − 𝑐12 + 𝑦 − 𝑐2

2 = 𝑐32

a point (x,y) in the Hough parameter space becomes a circle in the image.

For all (𝑐1, 𝑐2) where b(𝑐1, 𝑐2)!=0 For all (x,y,c3) where 𝑥 − 𝑐1

2 + 𝑦 − 𝑐22 = 𝑐3

2 c(x,y, c3):= c(x,y, c3) + b(𝑐1, 𝑐2) END END

Hough transform

Page 34: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Calculation of the Hough transform for circles

34

(α − x)2+(β − y)2 = 𝑟2

Page 35: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Example: circle detection by Hough transform

35

Page 36: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Corner detection ->

36

• Harris corner detector

C.Harris, M.Stephens. “A Combined Corner and Edge Detector”. 1988

Page 37: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

The Basic Idea ->

37

• We should easily recognize the point by looking through a small window

• Shifting a window in any direction should give a large change in intensity

Page 38: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Harris Detector: Basic Idea ->

38

“flat” region:

no change in

all directions

“edge”:

no change along

the edge direction

“corner”:

significant change

in all directions

Page 39: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Harris Detector: Mathematics ->

39

2

,

( , ) ( , ) ( , ) ( , )x y

E u v w x y I x u y v I x y

Change of intensity for the shift [u,v]:

Intensity Shifted intensity

Window function

or Window function w(x,y) =

Gaussian 1 in window, 0 outside

Page 40: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Harris Detector: Mathematics ->

40

( , ) ,u

E u v u v Mv

For small shifts [u,v] we have a bilinear approximation:

2

2,

( , )x x y

x y x y y

I I IM w x y

I I I

where M is a 22 matrix computed from image derivatives:

Page 41: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Harris Detector: Eigenvalue Analysis ->

41

( , ) ,u

E u v u v Mv

Intensity change in shifting window: eigenvalue analysis

1, 2 – eigenvalues of M

direction of the

slowest change

(max)-1/2 Ellipse E(u,v) = const

direction of the

fastest change

(max)-1/2

(min)-1/2

Page 42: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Eigenvalues Carry Clues ->

42 1

2

“Corner”

1 and 2 are large,

1 ~ 2;

E increases in all

directions

1 and 2 are small;

E is almost constant

in all directions

“Edge”

1 >> 2

“Edge”

2 >> 1

“Flat”

region

Classification of

image points using

eigenvalues of M:

Page 43: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Corner Response Measure ->

43

Measure of corner response:

2

det traceR M k M

1 2

1 2

det

trace

M

M

(k – empirical constant, k = 0.04-0.06)

Note that other definition of corner response measure also exists

Page 44: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Contour plot of Harris cornerness ->

44

Page 45: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Harris Detector: Mathematics ->

45 1

2 “Corner”

“Edge”

“Edge”

“Flat”

• R depends only on

eigenvalues of M

• R is large for a corner

• R is negative with large

magnitude for an edge

• |R| is small for a flat

region

R > 0

R < 0

R < 0 |R| small

Page 46: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

การเซกเมนตขอมลภาพเกรยสเกลโดยหาคาพกด (Grey-Scale Thresholding)

46

Grey-Scale Thresholding

Global Thresholding Local Thresholding

Adaptive Thresholding

Page 47: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Global Thresholding ->

47

𝐵 𝑚, 𝑛 = 1, 𝑖𝑓 𝑓 𝑚, 𝑛 ≥ 𝑇

0, 𝑖𝑓 𝑓 𝑚, 𝑛 < 𝑇

ปญหาทส าคญของวธนคอจะหาคา T ทเหมาะสมกบแตละภาพไดอยางไร?

ใชไดดกบภาพทวตถกบฉากหลงแยกกนชดเจน สงเกตได จาก Histogram ของภาพเปนแบบ multimodal

0 50 100 150 200 250

0

100

200

300

400

500

T = 102

สของแบคทเรย

สของฉากหลง

Page 48: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Region based segmentation

48

เปนวธการแยกองคประกอบของภาพโดยดจากต าแหนงของพกเซลและความเหมอนกนของ คณสมบตของพกเซลภายในพนท โดยถาพกเซลทอยตดกนและมคณสมบตเหมอนกนจะถกจด ใหเขากลมเดยวกน ขอดของการท าเชนนจะไดพนททตอเนอง

ตวอยางวธการ Region oriented image segmentation 1. Region Growing

2. Region Splitting and Merging

P

Pixel P and

its neighbors

Connected

pixels

Page 49: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Region Growing Algorithm

49

เรมจาก seed pixel ท าการรวมกลมพกเซลขาง เคยงทมคณสมบตเหมอนกนใหพนทโตขนเรอยๆ

พนทเรมขยายตว

การท างานจะหยดเมอไมสามารถขยายพนทออก ไปไดมากกวาน (เมอชนกบขอบของวตถ)

Page 50: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Watershed Transform -> • ในทางภมศาสตร

watershed เปนสนปนน า ทแยกอางน าในแตละแหลง

• แนวคดของ Watershed transform ทใชในการประมวลผลภาพเกรยสเกล จะใชในการแบงแยกวตถในภาพ โดยใชหลกการเดยวกบอางเกบน า

50

Page 51: การแบ่งขอ้มูลภาพstaff.cs.psu.ac.th/sathit/344-671/Image Segmentation.pdf · • จะใช้ลาปลาเชี ... max) -1/2 direction of

Watershed Transform ->

51

จากภาพ เมอระดบน าในอางเพมขนเรอยๆ กจะเหนเฉพาะขอบของอางเกบน า • เมอเทยบกบภาพเกรยสเกล

คาความเขมในแตละพนทจะไมเทากน สวนทเปนทลม กคอพนททมคาความเขมนอย

• สวนน าจะเปรยบไดกบระดบคาเทรสโฮลด เมอก าหนดใหคาสงขนกจะคลมพนทไดมากขน และจะใชแบงแตละพนทออกจากกน