使用 OpenCV 对图像执行白帽黑帽操作


在本程序中,我们将使用 OpenCV 对图像执行黑帽操作。黑帽变换用于增强亮背景中的黑暗目标。我们将使用形态学 ex(图像,cv2.MORPH_BLACKHAT,内核) 函数。

原图像

算法

Step 1: Import cv2.
Step 2: Read the image.
Step 3: Define the kernel size.
Step 4: Pass the image and kernel to the cv2.morphologyex() function.
Step 5: Display the output.

示例代码

import cv2

image = cv2.imread('image_test.jpg')
filter_size = (5,5)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, filter_size)
image = cv2.morphologyEx(image, cv2.MORPH_BLACKHAT, kernel)

cv2.imshow('BlackHat', image)

输出

更新时间:2021 年 3 月 17 日

316 次浏览

开启你的职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.