text: # -*- coding: utf-8 -*-
  
  import numpy as np
  import cv2
  import os
  from matplotlib import pyplot as plt
  
  
  def test1():
      img = cv2.imread('./../img/human.jpg', 0)
      ret, thresh1 = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)
      ret, thresh2 = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY_INV)
      ret, thresh3 = cv2.threshold(img, 127, 255, cv2.THRESH_TRUNC)
      ret, thresh4 = cv2.threshold(img, 127, 255, cv2.THRESH_TOZERO)
      ret, thresh5 = cv2.threshold(img, 127, 255, cv2.THRESH_TOZERO_INV)
  
      titles = ['Original Image', 'BINARY', 'BINARY_INV', 'TRUNC', 'TOZERO', 'TOZERO_INV']
      images = [img,  thresh1,  thresh2,  thresh3,  thresh4,  thresh5]
  
      for i in xrange(6):
          plt.subplot(2, 3, i + 1), plt.imshow(images[i], 'gray')
          plt.title(titles[i])
          plt.xticks([]), plt.yticks([])
  
      plt.show()
  
  
  def test2():
  
      img = cv2.imread('./../img/human.jpg', 0)
      img = cv2.medianBlur(img, 5)
  
      ret, th1 = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)
      th2 = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 11, 2)
      th3 = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
  
      titles = ['Original Image',  'Global Thresholding (v = 127)', 'Adaptive Mean Thresholding',  'Adaptive Gaussian Thresholding']
      images = [img,  th1,  th2,  th3]
  
      for i in xrange(4):
          plt.subplot(2, 2, i + 1), plt.imshow(images[i], 'gray')
          plt.title(titles[i])
          plt.xticks([]), plt.yticks([])
      plt.show()
  
  
  if __name__ == '__main__':
      test2()
  