Skip to content

Instantly share code, notes, and snippets.

@Praveen76
Created April 15, 2022 17:16
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/80774469c861dfb2b785e2fbfa60854a to your computer and use it in GitHub Desktop.
Save Praveen76/80774469c861dfb2b785e2fbfa60854a 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:\otsu.jpg')
cv.imshow('park',img)
#gloabl thresholding
ret1,th1=cv.threshold(img,150,255,cv.THRESH_BINARY)
#OTSU Thresholding
ret2,th2=cv.threshold(img,0,255,cv.THRESH_BINARY+cv.THRESH_OTSU)
'''#OTSU Thresholding after Gaussian Filtering
blur=cv.GaussianBlur(img,(5,5),0)
ret3,th3=cv.threshold(blur,0,255,cv.THRESH_BINARY+cv.THRESH_OTSU)
'''
cv.imwrite('gloabal thresh(v=150).jpg,th1)
cv.imwrite('otsu binarization.jpg',th2)
cv.imshow('gloabal thresh(v=150)',th1)
cv.imshow('otsu binarization',th2)
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