การแบ่งส่วนด้วย Superpixel
ในแบบฝึกหัดนี้ คุณจะนำ unsupervised segmentation มาใช้กับภาพเดิม ก่อนที่จะส่งต่อไปยังโมเดล machine learning สำหรับตรวจจับใบหน้า
โดยจะลดขนาดภาพจาก \(265 \times 191 = 50,615\) พิกเซล ให้เหลือเพียง \(400\) บริเวณ
face_imageฟังก์ชัน show_image() ก็ถูกโหลดไว้ให้แล้วเช่นกัน
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การประมวลผลภาพด้วย Python
คำแนะนำการฝึกหัด
- นำเข้าฟังก์ชัน
slic()จากโมดูลsegmentation - นำเข้าฟังก์ชัน
label2rgb()จากโมดูลcolor - สร้าง segmentation ที่มี 400 บริเวณโดยใช้
slic() - วาง segments ทับบนภาพต้นฉบับเพื่อเปรียบเทียบด้วย
label2rgb()
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Import the slic function from segmentation module
from skimage.____ import ____
# Import the label2rgb function from color module
from skimage.____ import ____
# Obtain the segmentation with 400 regions
segments = ____(____, ____= ____)
# Put segments on top of original image to compare
segmented_image = ____(____, ____, kind='avg')
# Show the segmented image
show_image(segmented_image, "Segmented image, 400 superpixels")