Adaptive Threshold
import cv2
img_color = cv2.imread('img/paper.jpg', 0)
cv2.imshow('Color', img_color)
cv2.waitKey(0)
ret, img_binary = cv2.threshold(img_color, 127,255, cv2.THRESH_BINARY)
cv2.imshow('Binary', img_binary)
cv2.waitKey(0)
img_result2 = cv2.adaptiveThreshold(img_color, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 21, 5)
#세번째 인자 적응형 이진화
#다섯번째 인자는 임계값 계산 시 함께 볼 주변 픽셀의 범위를 블럭 크기로 지정.
#여섯번째 인자는 평균 또는 가중평균에서 뺄 값
cv2.imshow('Adaptive1',img_result2)
cv2.waitKey(0)
img_result3 = cv2.adaptiveThreshold(img_color, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 21, 5)
#세번째 인자 가우시안 이진화
cv2.imshow('Adaptive2',img_result3)
cv2.waitKey(0)
img_result4 = cv2.adaptiveThreshold(img_result2, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 21, 5)
cv2.imshow('Adaptive3',img_result4)
cv2.waitKey(0)
cv2.destroyAllWindows()