本文整理匯總了Python中cv2.MORPH_BLACKHAT屬性的典型用法代碼示例。如果您正苦於以下問題:Python cv2.MORPH_BLACKHAT屬性的具體用法?Python cv2.MORPH_BLACKHAT怎麽用?Python cv2.MORPH_BLACKHAT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類cv2
的用法示例。
在下文中一共展示了cv2.MORPH_BLACKHAT屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: maximizeContrast
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import MORPH_BLACKHAT [as 別名]
def maximizeContrast(imgGrayscale):
height, width = imgGrayscale.shape
imgTopHat = np.zeros((height, width, 1), np.uint8)
imgBlackHat = np.zeros((height, width, 1), np.uint8)
structuringElement = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
imgTopHat = cv2.morphologyEx(imgGrayscale, cv2.MORPH_TOPHAT, structuringElement)
imgBlackHat = cv2.morphologyEx(imgGrayscale, cv2.MORPH_BLACKHAT, structuringElement)
imgGrayscalePlusTopHat = cv2.add(imgGrayscale, imgTopHat)
imgGrayscalePlusTopHatMinusBlackHat = cv2.subtract(imgGrayscalePlusTopHat, imgBlackHat)
return imgGrayscalePlusTopHatMinusBlackHat
# end function
示例2: process
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import MORPH_BLACKHAT [as 別名]
def process(self, cv_before, name):
k = self.k[0]
kernel = np.ones((k, k), np.uint8)
if name == 'Invert':
cv_before = cv2.cvtColor(cv_before, cv2.COLOR_RGB2GRAY)
cv_after = cv2.bitwise_not(cv_before)
elif name == 'Histogram Equalization':
cv_before = cv2.cvtColor(cv_before, cv2.COLOR_RGB2GRAY)
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
cv_after = clahe.apply(cv_before)
elif name == 'Threshold':
cv_before = cv2.cvtColor(cv_before, cv2.COLOR_RGB2GRAY)
ret, cv_after = cv2.threshold(
cv_before, k, 255, cv2.THRESH_BINARY)
elif name == 'Gaussian Threshold':
cv_before = cv2.cvtColor(cv_before, cv2.COLOR_RGB2GRAY)
cv_after = cv2.adaptiveThreshold(cv_before, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
cv2.THRESH_BINARY, k, 2)
elif name == 'HSV':
cv_before = cv2.cvtColor(cv_before, cv2.COLOR_RGB2HSV)
lower_color = np.array([k - 35, 0, 0])
upper_color = np.array([k + 35, 255, 255])
cv_after = cv2.inRange(cv_before, lower_color, upper_color)
elif name == 'LAB':
cv_before = cv2.cvtColor(cv_before, cv2.COLOR_RGB2LAB)
L, a, b = cv2.split(cv_before)
ret, cv_after = cv2.threshold(L, k, 255, cv2.THRESH_BINARY)
elif name == 'Erosion':
cv_before = cv2.cvtColor(cv_before, cv2.COLOR_RGB2GRAY)
cv_after = cv2.erode(cv_before, kernel, iterations=1)
elif name == 'Dilation':
cv_before = cv2.cvtColor(cv_before, cv2.COLOR_RGB2GRAY)
cv_after = cv2.dilate(cv_before, kernel, iterations=1)
elif name == 'Opening':
cv_before = cv2.cvtColor(cv_before, cv2.COLOR_RGB2GRAY)
cv_after = cv2.morphologyEx(
cv_before, cv2.MORPH_OPEN, kernel)
elif name == 'Closing':
cv_before = cv2.cvtColor(cv_before, cv2.COLOR_RGB2GRAY)
cv_after = cv2.morphologyEx(
cv_before, cv2.MORPH_CLOSE, kernel)
elif name == 'Top Hat':
cv_before = cv2.cvtColor(cv_before, cv2.COLOR_RGB2GRAY)
cv_after = cv2.morphologyEx(
cv_before, cv2.MORPH_TOPHAT, kernel)
elif name == 'Black Hat':
cv_before = cv2.cvtColor(cv_before, cv2.COLOR_RGB2GRAY)
cv_after = cv2.morphologyEx(
cv_before, cv2.MORPH_BLACKHAT, kernel)
elif name == 'Canny':
cv_before = cv2.cvtColor(cv_before, cv2.COLOR_RGB2GRAY)
cv_after = cv2.Canny(cv_before, 100, k)
elif name == 'Laplacian':
cv_before = cv2.cvtColor(cv_before, cv2.COLOR_RGB2GRAY)
cv_after = cv2.Laplacian(cv_before, cv2.CV_64F)
cv_after = np.absolute(cv_after)
cv_after = np.uint8(cv_after)
return cv_after