การตรวจจับขอบ (Edge Detection)
ในแบบฝึกหัดนี้ จะได้ลองตรวจจับขอบในภาพโดยใช้ฟิลเตอร์ Sobel
soaps_imageฟังก์ชัน show_image() ถูกโหลดไว้ให้เรียบร้อยแล้ว
มาดูกันว่าฟิลเตอร์นี้จะตรวจจับรูปทรงต่าง ๆ ในภาพได้ครบหรือไม่
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การประมวลผลภาพด้วย Python
คำแนะนำการฝึกหัด
- นำเข้าโมดูล
colorเพื่อแปลงภาพให้เป็นโทนสีเทา - นำเข้าฟังก์ชัน
sobel()จากโมดูลfilters - แปลง
soaps_imageเป็นภาพโทนสีเทาโดยใช้เมธอดที่เหมาะสมจากโมดูลcolor - นำฟิลเตอร์ตรวจจับขอบ Sobel ไปใช้กับภาพโทนสีเทา
soaps_image_grayที่ได้มา
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Import the color module
from ____ import ____
# Import the filters module and sobel function
from skimage.____ import ____
# Make the image grayscale
soaps_image_gray = ____.____(soaps_image)
# Apply edge detection filter
edge_sobel = ____(____)
# Show original and resulting image to compare
show_image(soaps_image, "Original")
show_image(edge_sobel, "Edges with Sobel")