Created
March 27, 2020 05:19
-
-
Save THEFASHIONGEEK/f9e82e5dc7de0420019a384e3364dcc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
from matplotlib import pyplot as plt | |
img = cv2.imread("imgs/chapter5/text2.png", 0); | |
#img = cv2.blur(img, (3, 3)) | |
# threshold -> 127 | |
# maxval -> 255 | |
# Output: | |
# 0-127 -> 0 | |
# 127-255 -> 255 | |
ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY) | |
thresh2 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,95,2) | |
f = plt.figure(figsize=(15,25)) | |
f.add_subplot(3, 1, 1).set_title('Original Image'); | |
plt.imshow(img, cmap = "gray") | |
f.add_subplot(3, 1, 2).set_title('Simple Thresholded Image'); | |
plt.imshow(thresh1, cmap = "gray"); | |
f.add_subplot(3, 1, 3).set_title('Adaptive Thresholded Image'); | |
plt.imshow(thresh2, cmap = "gray"); | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment