Skip to content

Instantly share code, notes, and snippets.

@Praveen76
Created April 15, 2022 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Praveen76/cd40824fdbb4b14d7a88b156f6c95063 to your computer and use it in GitHub Desktop.
Save Praveen76/cd40824fdbb4b14d7a88b156f6c95063 to your computer and use it in GitHub Desktop.
img=cv.imread('D:\image.jpg')
cv.imshow('img',img)
img=cv.cvtColor(img,cv.COLOR_BGR2GRAY)
ret,thresh1 = cv.threshold(img,120,255, cv.THRESH_BINARY)
ret,thresh2 = cv.threshold(img,120,255, cv.THRESH_BINARY_INV)
ret,thresh3 = cv.threshold(img,120,255, cv.THRESH_TRUNC)
ret,thresh4 = cv.threshold(img,120,255, cv.THRESH_TOZERO)
ret,thresh5 = cv.threshold(img,120,255, cv.THRESH_TOZERO_INV)
#Windows showing output images with the corresponding thresholding techniques applied to the input images
cv.imshow('Binary Threshold',thresh1)
cv.imshow('Binary Threshold Inverted',thresh2)
cv.imshow('Truncated Threshold',thresh3)
cv.imshow('Set to 0',thresh4)
cv.imshow('Set to 0 Inverted',thresh5)
#Deallocate any associated memory usage
if cv.waitKey(0) & 0*ff == 27:
cv.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment