Created
March 23, 2019 09:38
-
-
Save saurabhpal97/7e33d23f5413e89056b3977f91778439 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 the libraries | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import cv2 | |
%matplotlib inline | |
#ADAPTIVE THRESHOLDING | |
gray_image = cv2.imread('index.png',0) | |
ret,thresh_global = cv2.threshold(gray_image,127,255,cv2.THRESH_BINARY) | |
#here 11 is the pixel neighbourhood that is used to calculate the threshold value | |
thresh_mean = cv2.adaptiveThreshold(gray_image,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,11,2) | |
thresh_gaussian = cv2.adaptiveThreshold(gray_image,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2) | |
names = ['Original Image','Global Thresholding','Adaptive Mean Threshold','Adaptive Gaussian Thresholding'] | |
images = [gray_image,thresh_global,thresh_mean,thresh_gaussian] | |
for i in range(4): | |
plt.subplot(2,2,i+1),plt.imshow(images[i],'gray') | |
plt.title(names[i]) | |
plt.xticks([]),plt.yticks([]) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment