Sharpening Spatial Filters
Sharpening Spatial Filters
Sharpening
• วตัถปุระสงค์หลกัของ sharpening คือต้องการเพิ่มรายละเอียดหรือปรับปรุงรายละเอียดของภาพ เช่นในกรณีท่ีภาพเบลอท่ีเกิดจากความผิดพลาดหรือผลโดยธรรมชาติของการได้มาซึง่ข้อมลูภาพ(image acquisition)
• Sharpening ถกูน ามาใช้อย่างกว้างขวาง เช่นในการพิมพ์ภาพ Medical image, Remote sensing, Industrial inspection, และทางด้านการทหารที่ใช้ระบบน าทางอตัโนมตัิ เป็นต้น
Image differentiation
• การเฉลี่ยข้อมลูเปรียบได้กบัการอินติเกรต
• Sharpening ด าเนินการได้โดยการดิฟเฟอเรนติเอชนัในสปาเทียลโดเมน
• โดยปกติผลท่ีได้จาก ตวัด าเนินการเกรเดียนต์ จะเป็นสดัสว่นกบัระดบัความไมต่อ่เน่ืองในข้อมลูภาพ
• เกรเดียนต์ของภาพใช้ปรับปรุงขอบของวตัถใุนภาพ จดุท่ีไม่ตอ่เน่ืองอ่ืนๆท่ีปรากฏอยูใ่นภาพ(สญัญาณรบกวน) และเกรเดียนต์จะไปลดความเข้มของข้อมลูในพืน้ท่ีท่ีไมมี่การเปลี่ยนแปลงของข้อมลู
Foundation
• เกรเดียนต์ในปริภมูิหนึง่มิติ เราสนใจพฤติกรรมของอเกรเดียนต์ในช่วงตา่งๆของระดบัสีเทาท่ีคงท่ี(Flat segments) และสว่นท่ีไมต่อ่เน่ืองเช่นสว่นท่ีมีความชนั(Ramp) และท่ีความชนัเทา่กบั 90 องศาหรือท่ีเรียกวา่ “Step”
• ความไม่ตอ่เน่ืองท่ีถกูเน้นด้วยเกรเดียนต์ สามารถจ าลองจดุท่ีเป็นสญัญาณรบกวน เส้นตรง และขอบของวตัถท่ีุปรากฏอยูใ่นภาพ
• คณุสมบตัิของผลลพัธ์จากเกรเดียนต์ท่ีน่าสนใจอีกอย่างหนึง่คือ การเปลี่ยนแปลงท่ีจะเข้าสูแ่ละออกจากจดุท่ีมีคณุสมบตัิท่ีส าคญั (image features)
Foundation
• first derivative (1) must be zero in flat segments (areas of constant gray-
level values); (2) must be nonzero at the onset of a gray-level step or
ramp; and (3) must be nonzero along ramps.
Similarly, any definition of • second derivative
(1) must be zero in flat areas; (2) nonzero at the onset and end of a gray-level step or
ramp; and (3) must be zero along ramps of constant slope.
First-order derivative of f( x) defined as
𝜕𝑓
𝜕𝑥= 𝑓 𝑥 + 1 − 𝑓(𝑥)
A second-order derivative as the difference
𝜕2𝑓
𝜕𝑥2= 𝑓 𝑥 + 1 + 𝑓(𝑥 − 1) − 2𝑓(𝑥)
Example 1st and 2nd derivative
Image contains various solid objects, a line, and a single noise point.
0 50 100 150 200 250 300 350 400 450 5000
50
100
150
200
250
• Graph shows a horizontal gray-level profile (scan line) of the image along the center and including the noise point.
• This profile is the one-dimensional function we will use for illustrations regarding this figure.
Example 1st and 2nd derivative
ในรูปแสดงโพรไฟล์ ท่ีแทนด้วยตวัเลขท่ีสเกลลงมาเพื่อความสะดวกในการแทน ง่ายตอ่การด าเนินการ และการวิเคราะห์พฤติกรรมของอนพุนัธ์อนัดบัท่ีหนึง่และท่ีสอง เม่ือข้อมลูประกอบด้วยสญัญาณรบกวน ช่วงท่ีไม่มีการเปลี่ยนแปลง ขอบวตัถ ุเป็นต้น
0 50 100 150 200 250 300 350 400 450 5000
50
100
150
200
250
1st =f(x+1)-f(x) = 4-5=-1
0 50 100 150 200 250 300 350 400 450 5000
50
100
150
200
250
2nd =f(x+1)+f(x-1)-2f(x) = 4+5-2(5)=-1
• First-order derivative is nonzero along the entire ramp, • The second-order derivative is nonzero only at the onset
and end of the ramp. • Because edges in an image resemble this type of transition, • Conclude:
– first-order derivatives produce "thick" edges and – Second-order derivatives, much finer ones.
• The isolated point response at around the point is much stronger for the second derivative.
• A second-order derivative is much more aggressive than a first-order derivative in enhancing sharp changes.
• So that, we can expect a second-order derivative to enhance fine detail (including noise) much more than a first-order derivative.
The thin line is a fine detail, • If the maximum gray level of the line had been the same as
the isolated point, • the response of the second derivative would have been
stronger for the latter.
Step Edge
• Response of the two derivatives is the same at the gray-Ievel step
• The second derivative has a transition from positive back to negative.
• In an image, this shows as a thin double line or "double-edge“.
• If the gray level of the thin line had been the same as the step,
• the response of the second derivative would have been stronger for the line than for the step.
Comparing the response between first- and second-order derivatives
(1) First-order derivatives generally produce thicker edges in an image.
(2) Second-order derivatives have a stronger response to fine detail, such as thin lines and isolated points.
(3) First order derivatives generally have a stronger response to a gray-level step.
(4) Second-order derivatives produce a double response at step changes in gray level.
Note: for 2nd derivatives , similar changes in gray-level values, their response is stronger to a line than to a step, and to a point than to a line.
1st and 2nd Derivative
• การประยกุต์ในการปรับปรุงข้อมลูภาพสว่นใหญ่ อนพุนัธ์อนัดบัสองจะมีความเหมาะสมกวา่อนัดบัหนึง่ เน่ืองจากสามารถปรับปรุงรายละเอียดของวตัถใุนภาพได้ดีกวา่
• ส าหรับอนพุนัธ์อนัดบัท่ีหนึง่จะน ามาอธิบายในหวัข้อถดัไป เน่ืองจากจะน าไปใช้ในการหาขอบของวตัถใุนภาพ แตก็่สามารถน ามาใช้ร่วมกบัอนพุนัธ์อนัดบัท่ีสอง เพ่ือการปรับปรุงภาพได้
การใช้อนพุนัธ์อนัดบัสองในการปรับปรุงภาพ
• น ามาสร้างตวักรองสญัญาณภาพ แบบไมมี่ทิศทาง (Isotropic Filter) นัน่คือไมว่า่จะหมนุข้อมลูภาพไปในทิศทางใด เม่ือประมวลกบั Isotropic Filter ก็จะได้ผลลพัธ์เหมือนกนั
• น ามาใช้ในวิธีลาปลาเซียน (Laplacian) ซึง่เป็นตวัด าเนินการอย่างง่ายท่ีสดุ ท่ีใช้สร้างตวักรองแบบไมมี่ทิศทาง ตวัด าเนินการลาปลาเซียนของรูปภาพ f(x,y) ท่ีมีสองตวัแปรสามารถก าหนดได้ดงันี ้
𝛻2𝑓 =𝜕2𝑓
𝜕𝑥2+𝜕2𝑓
𝜕𝑦2
ลาปลาเชียลแบบไมต่อ่เน่ือง
• ใช้ปรับปรุงภาพดจิิทลั การหาอนพุนัธ์จะต้องใช้ข้อมลูในบริเวณ
ใกล้เคียงมาค านวณ 𝛻2𝑓 =𝜕2𝑓
𝜕𝑥2 +𝜕2𝑓
𝜕𝑦2
• 2nd Derivative of horizontal direction 𝜕2𝑓
𝜕𝑥2= 𝑓 𝑥 − 1, 𝑦 + 𝑓 𝑥 + 1, 𝑦 − 2𝑓(𝑥, 𝑦)
• 2nd Derivative of vertical direction 𝜕2𝑓
𝜕𝑦2= 𝑓 𝑥, 𝑦 − 1 + 𝑓 𝑥, 𝑦 + 1 − 2𝑓(𝑥, 𝑦)
ลาปลาเชียลสองมิติ
2nd Derivative of x and y:
𝛻2𝑓 = 𝑓 𝑥 − 1, 𝑦 + 𝑓 𝑥 + 1, 𝑦 + 𝑓 𝑥, 𝑦 − 1
+ 𝑓 𝑥, 𝑦 + 1 − 4𝑓 𝑥, 𝑦
𝛻2𝑓 =
0 𝑓(𝑥 − 1, 𝑦) 0𝑓(𝑥, 𝑦 − 1) −4𝑓(𝑥, 𝑦) 𝑓(𝑥, 𝑦 + 1)
0 𝑓(𝑥 + 1, 𝑦) 0 (1)
ลาปลาเชียลสองมิติ 90 Isotropic: เม่ือหมนุรูปทกุๆ 90 องศาจะได้ผลลพัธ์ท่ีเหมือนกนั Diagonal operator: • Horizontal direction 𝜕2𝑓
𝜕𝑥2= 𝑓 𝑥 − 1, 𝑦 − 1 + 𝑓 𝑥 + 1, 𝑦 + 1 − 2𝑓(𝑥, 𝑦)
• Vertical direction 𝜕2𝑓
𝜕𝑦2= 𝑓 𝑥 − 1, 𝑦 + 1 + 𝑓 𝑥 + 1, 𝑦 − 1 − 2𝑓(𝑥, 𝑦)
• Diagonal Laplacial operator
𝛻2𝑓 =
𝑓(𝑥 − 1, 𝑦 − 1) 0 𝑓(𝑥 − 1, 𝑦 + 1)0 −4𝑓(𝑥, 𝑦) 0
𝑓(𝑥 + 1, 𝑦 − 1) 0 𝑓(𝑥 + 1, 𝑦 + 1) (2)
ลาปลาเชียลสองมิติ
From Eq. (1) and (2), 45 operator
𝛻2𝑓 = 𝑓 𝑥, 𝑦−1,−1 −1,0 −1,10,−1 −8 0,0 0,11,−1 1,0 1,1
(3)
Variation of Eq. (1) and (3), 3×3 neighborhood pixel
𝑊4: 0 1 01 −4 10 1 0
0 −1 0−1 4 −10 −1 0
𝑊8: 1 1 11 −8 11 1 1
−1 −1 −1−1 8 −1−1 −1 −1
Composite Laplacian Mask
𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 − 𝛻2𝑓 𝑥, 𝑦 กรณีท่ีสมาชิกตรงกลางลาปลาเชียลติดลบ𝑓 𝑥, 𝑦 + 𝛻2𝑓 𝑥, 𝑦 กรณีท่ีสมาชิกตรงกลางลาปลาเชียลเป็นบวก
(4)
𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 − 𝑓 𝑥, 𝑦 ∗ 𝑤4 𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 − 𝑓 𝑥, 𝑦 ∗ 𝑤8
(ก) (ข) (ค) (ง)
(ก) รูปขัว้เหนือของดวงจนัทร์ (ข) ผลจากลาปลาเชียล
0 1 01 −4 10 1 0
(ค) ผลจากลาปลาเชียลในโดเมนของทศนิยม >>f = im2double(f); >>g2=imfilter(f,w,’replicate’); >>imshow(g2,[]); (ง) Image sharpening โดยการ >>g = f – g2;
สมการที่ (4) ท่ีนิยามไว้วา่ 𝑔 𝑥, 𝑦
= 𝑓 𝑥, 𝑦 − 𝛻2𝑓 𝑥, 𝑦 กรณีท่ีสมาชิกตรงกลางลาปลาเชียลติดลบ𝑓 𝑥, 𝑦 + 𝛻2𝑓 𝑥, 𝑦 กรณีท่ีสมาชิกตรงกลางลาปลาเชียลเป็นบวก
(4)
เม่ือลาปลาเชียล 𝛻2𝑓 𝑥, 𝑦 แทนด้วยสมการที่ (1) จะสามารถจดัรูปเสียใหม่เป็น
𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦− 𝑓 𝑥 − 1, 𝑦 + 𝑓 𝑥, 𝑦 − 1 + 𝑓 𝑥, 𝑦 + 1+ 𝑓 𝑥 + 1, 𝑦 + 4𝑓 𝑥, 𝑦= 5𝑓 𝑥, 𝑦− 𝑓 𝑥 − 1, 𝑦 + 𝑓 𝑥, 𝑦 − 1 + 𝑓 𝑥, 𝑦 + 1+ 𝑓 𝑥 + 1, 𝑦 (5)
จากสมการที่ (4) เม่ือแทนลาปลาเชียลด้วยสมการที่ (3) ก็จะได้วินโดว์ของการท า Sharpening ดงันี ้
Sharpening operator
𝑊4 =0 −1 0−1 5 −10 −1 0
𝑊8 =−1 −1 −1−1 9 −1−1 −1 −1
Unsharp masking and high-boost filtering
• There have been many variants of this basic idea proposed in the literature.
𝑔𝑠 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 − 𝑓 𝑥, 𝑦 (6)
• กระบวนการนีม้าจากการอดัฟิล์ม ซึง่ตอ่มา Unsharp masking ถกูพฒันามาเป็น High-boost filtering ท่ีมีการนิยามดงันี ้
𝑔ℎ𝑏 𝑥, 𝑦 = 𝐴𝑓 𝑥, 𝑦 − 𝑓 (𝑥, 𝑦)
high-boost filtering
𝑔ℎ𝑏 𝑥, 𝑦 = 𝐴𝑓 𝑥, 𝑦 − 𝑓 𝑥, 𝑦 (7)
โดยท่ี 𝐴 ≥ 1สมการนีส้ามารถน ามาจดัรูปเสียใหมโ่ดย 𝑔ℎ𝑏 𝑥, 𝑦
= 𝐴𝑓 𝑥, 𝑦 + 𝑓 𝑥, 𝑦 − 𝑓 𝑥, 𝑦 − 𝑓 𝑥, 𝑦= 𝐴 − 1 𝑓 𝑥, 𝑦 + 𝑓 𝑥, 𝑦 − 𝑓 𝑥, 𝑦= 𝐴 − 1 𝑓 𝑥, 𝑦 + 𝑔𝑠 𝑥, 𝑦 (8)
ในสมการท่ี (8) สามารถใช้ได้ทัว่ไป แตไ่มไ่ด้ก าหนดไว้ตรงๆวา่จะปรับภาพให้คมชดัได้อยา่งไร ดงันัน้ถ้าเลือกใช้ลาปลาเชียล 𝑔𝑠 𝑥, 𝑦 ก็จะได้จากสมการท่ี (4)
high-boost filtering
จากกรณีข้างต้น ท าให้สมการท่ี (8) กลายเป็น
𝑔ℎ𝑏 = 𝐴𝑓 𝑥, 𝑦 − 𝛻2𝑓 𝑥, 𝑦 ถ้าสมาชิกตรงกลางของลาปลาเชียลติดลบ𝐴𝑓 𝑥, 𝑦 + 𝛻2𝑓 𝑥, 𝑦 ถ้าสมาชิกตรงกลางของลาปลาเชียลเป็นบวก
(9)
การปรับภาพให้คมชดัด้วยตวักรอง high-boost มีรูปแบบของวินโดว์เป็นดงันี ้0 −1 0−1 𝐴 + 4 −10 −1 0
−1 −1 −1−1 𝐴 + 8 −1−1 −1 −1
>>g=imfilter(f,-w8, ‘replicate’);
A=1 A=1.7
การใช้อนพุนัธ์อนัดบัท่ีหนึง่ในการปรับปรุงภาพ
• เกรเดียนต์ท่ีโคออร์ดิเนต (x, y) จะถกูก าหนดเป็นสองมิติในรูปของคอลมัน์เวกเตอร์ดงันี ้
𝛻𝒇 =𝐺𝑥𝐺𝑦
=
𝜕𝑓
𝜕𝑥𝜕𝑓
𝜕𝑦
(10)
• ขนาดของเวกเตอร์นีถ้กู าหนดโดย
12
12
2 2
22
x y
f mag
G G
f f
x y
f
• องค์ประกอบตา่งๆท่ีได้จากเกรเดียนต์ จะเป็นเชิงเส้น แตข่นาดของเวกเตอร์ไมเ่ป็นเชิงเส้นเพราะ มีการยกก าลงัสองและการถอดรากท่ีสอง
• Eq.(10) จะมีทิศทางหรือเป็นเวกเตอร์ (non isotropic) แต่ขนาดจะไมเ่ป็นเวกเตอร์คือจะเป็น Isotropic
• การค านวณขนาดของเวกเตอร์ในการประมวลผลภาพ ปกติจะใช้วิธีประมาณคา่ด้วยคา่สมับรูณ์แทนการยกก าลงัสองและการถอดรากท่ีสอง
𝛻𝑓 ≈ 𝐺𝑥 + 𝐺𝑦
การใช้อนพุนัธ์อนัดบัท่ีหนึง่ในการปรับปรุงภาพ
การใช้อนพุนัธ์อนัดบัท่ีหนึง่ในการปรับปรุงภาพ
𝑓(𝑥 − 1, 𝑦 − 1) 𝑓(𝑥 − 1, 𝑦) 𝑓(𝑥 − 1, 𝑦 + 1)𝑓(𝑥, 𝑦 − 1) 𝑓(𝑥, 𝑦) 𝑓(𝑥, 𝑦 + 1)
𝑓(𝑥 + 1, 𝑦 − 1) 𝑓(𝑥 + 1, 𝑦) 𝑓(𝑥 + 1, 𝑦 + 1)
𝑧1 𝑧2 𝑧3𝑧4 𝑧5 𝑧6𝑧7 𝑧8 𝑧9
ดงันัน้ 𝐺𝑥 = 𝑓 𝑥 + 1, 𝑦 − 𝑓 𝑥, 𝑦 = 𝑧8 − 𝑧5 𝐺𝑦 = 𝑓 𝑥, 𝑦 + 1 − 𝑓 𝑥, 𝑦 = 𝑧6 − 𝑧5
• Roberts cross-gradient operators ได้นิยามไว้ดงันี ้𝐺𝑥 = 𝑓 𝑥 + 1, 𝑦 + 1 − 𝑓 𝑥, 𝑦 = 𝑧9 − 𝑧5 𝐺𝑦 = 𝑓 𝑥 + 1, 𝑦 − 𝑓 𝑥, 𝑦 + 1 = 𝑧8 − 𝑧6
• จะมีขนาดเป็น 𝛻𝑓 = 𝑧9 − 𝑧5
2 + 𝑧8 − 𝑧62 1 2
• ซึง่จะประมาณโดย 𝛻𝑓 ≈ 𝑧9 − 𝑧5 + 𝑧8 − 𝑧6 (11)
• เกรเดียนต์ในวินโดว์ 3×3 ท่ีน่าสนใจอีกตวัหนึง่คือ 𝛻𝑓 ≈ 𝑧7 + 2𝑧8 + 𝑧9 − 𝑧1 + 2𝑧2 + 𝑧3
+ 𝑧3 + 2𝑧6 + 𝑧9 − 𝑧1 + 2𝑧4 + 𝑧7 (12)
การใช้อนพุนัธ์อนัดบัท่ีหนึง่ในการปรับปรุงภาพ
• วินโดว์ท่ีได้จาก Roberts cross-gradient operators สมการท่ี (11) คือ
−1 00 1
0 −11 0
• Sobel operators จากสมการท่ี (12) คือ −1 −2 −10 0 01 2 1
−1 0 1−2 0 2−1 0 1
การใช้อนพุนัธ์อนัดบัท่ีหนึง่ในการปรับปรุงภาพ
%Laplacian >>g=imfilter(f, w8, ‘replicate’); %Sharpening image >> gs = f+g; %Sobel operators >>g1 = imfilter(f, w, ‘replicate’); >>g2 = imfilter(f, w’, ‘replicate’); >>g = abs(g1)+abs(g2); %Average 5x5 of Sobel operators >>g = imfilter(g, w5x5, ‘replicate’);