ในโปรแกรมนี้ เราจะดำเนินการเปิดบนรูปภาพ การเปิดจะนำวัตถุขนาดเล็กออกจากพื้นหน้าของรูปภาพ โดยวางไว้ในพื้นหลัง เทคนิคนี้สามารถใช้เพื่อค้นหารูปร่างเฉพาะในภาพได้ การเปิดสามารถเรียกได้ว่าการพังทลายตามด้วยการขยาย ฟังก์ชันที่เราจะใช้สำหรับงานนี้คือ cv2.morphologyEx(image, cv2.MORPH_OPEN, เคอร์เนล)
ภาพต้นฉบับ

อัลกอริทึม
Step 1: Import cv2 and numpy. Step 2: Read the image. Step 3: Define the kernel. Step 4: Pass the image and kernel to the cv2.morphologyex() function. Step 4: Display the output.
โค้ดตัวอย่าง
import cv2
import numpy as np
image = cv2.imread('testimage.jpg')
kernel = np.ones((5,5), np.uint8)
image = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel)
cv2.imshow('Opening', image) ผลลัพธ์
