ในโปรแกรมนี้ เราจะลงภาพตัวอย่าง การสุ่มตัวอย่างเป็นการลดความละเอียดเชิงพื้นที่ในขณะที่ยังคงการแสดงภาพ 2 มิติไว้ โดยทั่วไปจะใช้สำหรับการซูมภาพออก เราจะใช้ฟังก์ชัน pyrdown() ในไลบรารี openCV เพื่อทำงานนี้ให้เสร็จสิ้น
ภาพต้นฉบับ

อัลกอริทึม
Step 1: Fead the image. Step 2: Pass the image as a parameter to the pyrdown() function. Step 3: Display the output.
โค้ดตัวอย่าง
import cv2
image = cv2.imread('testimage.jpg')
print("Size of image before pyrDown: ", image.shape)
image = cv2.pyrDown(image)
print("Size of image after pyrDown: ", image.shape)
cv2.imshow('DownSample', image) ผลลัพธ์
Size of image before pyrDown: (350, 700, 3) Size of image after pyrDown: (175, 350, 3)

คำอธิบาย
หากเราสังเกตขนาดของภาพก่อนและหลังการใช้ฟังก์ชัน pyrDown เราจะเห็นว่าขนาดลดลง กล่าวคือ เราได้ลดขนาดภาพลง