Created
October 29, 2021 11:09
-
-
Save Yuktha-Majella/32b59640876940b69895160ba45aa22a 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 cv2 | |
import numpy as np | |
#import image as Gray-scale | |
img = cv.imread('C:\\Users\\Admin\\Downloads\\thresholding\\gradient.jpg',0) | |
#Different types of Simple Threshold | |
ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY) | |
ret,thresh2 = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV) | |
ret,thresh3 = cv2.threshold(img,127,255,cv2.THRESH_TRUNC) | |
ret,thresh4 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO) | |
ret,thresh5 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO_INV) | |
vis1 = np.concatenate((img, thresh1, thresh2), axis=1) | |
vis2 = np.concatenate((thresh3, thresh4, thresh5), axis=1) | |
cv2.imshow("ORIGINAL vs THRESH_BINARY vs THRESH_BINARY_INV", vis1) | |
cv2.imshow("THRESH_TRUNC vs THRESH_TOZERO vs THRESH_TOZERO_INV", vis2) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment