Skip to content

Instantly share code, notes, and snippets.

@Praveen76
Last active April 15, 2022 18:12
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/ff17aac658e1a03538de671806358b3b to your computer and use it in GitHub Desktop.
Save Praveen76/ff17aac658e1a03538de671806358b3b to your computer and use it in GitHub Desktop.
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
img = cv.imread('D:\image.jpg')
img=cv.medianBlue(img,5)
ret,th1=cv.threshold(img,255,cv.THRESH_BINARY)
th2=cv.adaptiveThreshold(img,255,cv.ADAPTIVE_THRESH_MEAN_C,cv.THRESH_BINARY,11,2)
th3=cv.adaptiveThreshold(img,255,cv.ADAPTIVE_THRESH_GAUSSIAN_C,cv.THRESH_BINARY,11,2)
#To save the image in working directory
cv.imwrite('original.jpg',img)
cv.imwrite('global thesh.jpg',th1)
cv.imwrite('adaptive mean.jpg',th2)
cv.imwrite('adaptive gaussian.jpg',th3)
cv.imshow('global thresh(v=100)',th1)
cv.imshow('adaptive mean Inverted',th2)
cv.imshow('adaptive gaussian Threshold',th3)
cv.imshow('original',img)
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