Binary Image Processing
Download
Report
Transcript Binary Image Processing
Lecture 2
Binary Image Processing
1
Gray Scale and Color Image
Gray = 0.299 * R + 0.587 * G + 0.114 * B
2
Gray Scale and Color Image
3
Histogram
4
Thresholding
5
Thresholding using Histogram
6
Thresholding by Photoshop
Figure / Ground Separation
แยกรู ป (Figure) ออกจากพื้นหลัง (background)
Algorithm for Threshold
if(pixel[row][column].color >=100)
pixel[row][column].color = 255
else
pixel[row][column].color = 0
7
Properties of Binary Image (1)
Area
0 means white (background)
8
Properties of Binary Image (2)
Position of Object
9
Properties of Binary Image (2)
Position of Object
X= 2(1)+3(3)+4(3)+5(8)+6(5)+7(5)+8(2)
= 2+9+12+40+30+35+16=144/27
= 5.33 = 5
Y= 2(1)+3(4)+4(5)+5(4)+6(3)+7(6)+8(3)+9(1)
= 2+12+20+20+18+42+24+9 = 147/27
= 5.44 = 5
Position of object = (5,5)
10
Properties of Binary Image (3)
Projection
11
Properties of Binary Image (3)
Projection
12
Blob Coloring (region
segment)
13
Neighboring System
14
Neighboring System
15
Line Segment Labeling
mask
NW
N
W
o
NE
16
Blob coloring example
mask
NW
N
W
o
NE
Equivalent set
17
Run length encoding
Binary image
Start and length of 1 runs : row1 = (1,3) (7,2) (12,4) (17,2) (20,3)
row2 = (5,13) (19,4)
row3 = (1,3) (17,6)
Length of 1 and 0 runs : row1 = (1,3) (0,3) (1,2) (0,3) (1,4) (0,1) (1,2) (0,1) (1,3)
row2 = (0,4) (1,13) (0,1) (1,4)
row3 = (1,3) (0,13) (1,6)
18
Chain Code
Contour คือเส้ นขอบทีแ่ สดงถึงรู ปร่ างของวัตถุในภาพ
Chain Code มีไว้ สาหรับแสดงทิศทางทีต่ ่ อเชื่อมถึงกันของ edge point ทีเ่ ป็ น
Contour โดยใช้ ตัวเลข
การหาทิศทางจาก Chain Code ให้ หาทิศทางตามเข็มนาฬิ กา
ในการหา Chain Code จะใช้ Mask 8 neighbors ซึ่งมีค่าดังนี้
2
3
4
1
x
5
8
7
6
X คือ pixel ปัจจุบัน
19
Chain Code
ก่อนที่จะทา Chain Code ของ Contour ใด
ๆ จะต้องทาการหาขอบของภาพก่อน
(Edge Detection) ซึ่งจะใช้การหาขอบ
แบบใดก็ได้ เช่น Robert, Prewitt, Canny
หลังจากทา Edge Detection แล้วให้
พิจารณาเฉพาะ pixel ที่เป็ นขอบเท่านั้นใน
การทา Chain Code
Edge Detection
20
Chain Code (Example)
Edge
Contour
Chain
Code
3 5 5
3 5 5 5 5 5
3
6
4
7
4
6 5 5 5
6 5 5
2
7
4
1 1 2
6
2
8
4
2
8
2
8
2
8
2
7
2
8
1 1 8
1 7
8
2
3
4
1
x
5
8
7
6
สามารถสรุป Chain code ดังนี้
6(2), 5(3), 4(1), 3(1), 5(5),
7(1), 6(1), 5(2), 7(1), 6(1),
8(1), 7(2), 1(1), 2(2), 8(2),
1(2), 2(1),4(1), 2(1),1(2),
8(4), 2(3),4(1), 2(1), 4(1),
3(2), 5(2)
21
Project
ให้นกั ศึกษาแบ่งกลุ่ม 5 กลุ่ม กลุ่มละ 4 คน เขียนโปรแกรม OCR ด้วยภาษา
โปรแกรม อะไรก็ได้ (ยกเว้น matlab) เพื่ออ่านภาพตัวอักษรภาษาอังกฤษ az, A-Z, 0-9, สัญลักษณ์สาคัญต่าง ๆ ที่ได้จากภาพจากการ scan โดย
scanner
โดยให้ใช้ตวั อักษร Arial ขนาด 12 ตัวปกติ
โดย Test image จะต้องไม่จากัดบรรทัดในการอ่าน และ output ที่
ออกมาจะต้องสามารถเว้นวรรค ขึ้นบรรทัดใหม่ได้เหมือน Test image
นักศึกษาต้องทารายงานการเขียนโปรแกรมพร้อมบอก Algorithm และแนวคิด
ต่าง ๆ ในการเขียนโปรแกรม และต้อง present หน้าชั้นเรี ยนด้วย (ทุกคนใน
กลุ่ม) ส่ งก่อนสอบ Final หนึ่งสัปดาห์
22
Assignment2
ให้นกั ศึกษาเขียนโปรแกรมกลุ่มละ 2 คน โดยให้ทาการรับภาพตัวอักษร
ภาษาอังกฤษ Arial ขนาด 12 เข้ามาโดยรับกี่บรรทัดก็ได้ แล้วให้ทาการตัด
บรรทัด แต่ละบรรทัดออกมาโดยใช้วธิ ี Horizontal Projection โดยแต่
ละบรรทัดที่ตดั ออกมาได้น้ นั ให้ Save ออกมาเป็ นไฟล์ภาพของแต่ละบรรทัดที่
ตัดได้
23