Created
March 23, 2019 09:36
-
-
Save saurabhpal97/ace84e0cba53197b928ade050f89e185 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
#importing the required libraries | |
import numpy as np | |
import cv2 | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
#here 0 means that the image is loaded in gray scale format | |
gray_image = cv2.imread('index.png',0) | |
ret,thresh_binary = cv2.threshold(gray_image,127,255,cv2.THRESH_BINARY) | |
ret,thresh_binary_inv = cv2.threshold(gray_image,127,255,cv2.THRESH_BINARY_INV) | |
ret,thresh_trunc = cv2.threshold(gray_image,127,255,cv2.THRESH_TRUNC) | |
ret,thresh_tozero = cv2.threshold(gray_image,127,255,cv2.THRESH_TOZERO) | |
ret,thresh_tozero_inv = cv2.threshold(gray_image,127,255,cv2.THRESH_TOZERO_INV) | |
#DISPLAYING THE DIFFERENT THRESHOLDING STYLES | |
names = ['Oiriginal Image','BINARY','THRESH_BINARY_INV','THRESH_TRUNC','THRESH_TOZERO','THRESH_TOZERO_INV'] | |
images = gray_image,thresh_binary,thresh_binary_inv,thresh_trunc,thresh_tozero,thresh_tozero_inv | |
for i in range(6): | |
plt.subplot(2,3,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