In [1]:
import cv2
In [2]:
# read the image as a grayscale
image = cv2.imread('car.jpg',0)
In [3]:
# Otsu's thresholding
ret1,th1 = cv2.threshold(image,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)

# Otsu's thresholding with Gaussian filtering
blurred = cv2.GaussianBlur(image,(5,5),0)
ret2,th2 = cv2.threshold(blurred,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
In [4]:
cv2.imshow("Otsu's thresholding", th1)
cv2.imshow("Otsu's thresholding with Gaussian filtering", th2)
cv2.waitKey(0)
cv2.destroyAllWindows();