cv2.threshold(): 이미지 임계처리
2023. 3. 27. 12:31ㆍOpenCV
cv2.threshold(src, thresh, maxval, type)
src – 입력 이미지
thresh – 임계값
maxval – 임계값을 넘었을 때 적용할 value
type – thresholding type
thresholding type
cv2.THRESH_BINARY
cv2.THRESH_BINARY_INV
cv2.THRESH_TRUNC
cv2.THRESH_TOZERO SDsd
cv2.THRESH_TOZERO_INV
예시
image = cv2.imread('DOG.jfif', 0)
plt.figure(figsize=(30, 30))
plt.subplot(3, 2, 1)
plt.title("Original")
plt.imshow(image)
ret,thresh1 = cv2.threshold(image, 127, 255, cv2.THRESH_BINARY)
plt.subplot(3, 2, 2)
plt.title("Threshold Binary")
plt.imshow(thresh1)
image = cv2.GaussianBlur(image, (3, 3), 0)
thresh = cv2.adaptiveThreshold(image, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 3, 5)
plt.subplot(3, 2, 3)
plt.title("Adaptive Mean Thresholding")
plt.imshow(thresh)
_, th2 = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
plt.subplot(3, 2, 4)
plt.title("Otsu's Thresholding")
plt.imshow(th2)
plt.subplot(3, 2, 5)
blur = cv2.GaussianBlur(image, (5,5), 0)
_, th3 = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
plt.title("Guassian Otsu's Thresholding")
plt.imshow(th3)
plt.show()
'OpenCV' 카테고리의 다른 글
cv2.resize(): 크기 조절 함수 (0) | 2023.03.28 |
---|---|
투시 변환 함수: cv2.getPerspectiveTransform, cv2.warpPerspective (0) | 2023.03.27 |
cv2.Sobel(): 소벨 필터를 이용한 미분 함수 (0) | 2023.03.27 |
cv2.cvtColor(): 색변환 함수 (0) | 2023.03.27 |
cv2.morphologyEx(): 모폴로지 함수(침식, 팽창, 오프닝, 클로징) (0) | 2023.03.27 |