In [2]:
%matplotlib inline
from matplotlib import pyplot as plt, cm
import cv2
from imutils.convenience import resize

In [6]:
# load the image and convert it to grayscale
image = cv2.imread("./data/thumb_IMG_4178_1024.jpg")
image = resize(image, height = 250)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# initialize the list of threshold methods
methods = [
    ("THRESH_BINARY", cv2.THRESH_BINARY),
    ("THRESH_BINARY_INV", cv2.THRESH_BINARY_INV),
    ("THRESH_TRUNC", cv2.THRESH_TRUNC),
    ("THRESH_TOZERO", cv2.THRESH_TOZERO),
    ("THRESH_TOZERO_INV", cv2.THRESH_TOZERO_INV)]
 
# loop over the threshold methods
for (threshName, threshMethod) in methods:
    # threshold the image and show it
    (T, thresh) = cv2.threshold(gray, 100, 255, threshMethod)
    plt.figure(figsize=(16,12))
    plt.subplot(111), plt.imshow(thresh, cmap = 'gray')
    plt.title(threshName)