Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3.  
  4. gray = cv2.imread('D:\PT\pic\pcg.jpg', cv2.IMREAD_GRAYSCALE)
  5. scalex = 0.5
  6. scaley = 0.5
  7. X, Y = gray.shape[1]*scalex, gray.shape[0]*scaley
  8. gray = cv2.resize(gray, (int(X), int(Y)))
  9.  
  10. binary_thresh, bin = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)
  11. Otsu_thresh, otsu = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU)
  12. triangle_thresh, tri = cv2.threshold(gray, 0, 255, cv2.THRESH_TRIANGLE)
  13. adapt = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
  14. cv2.THRESH_BINARY, 13, 15)
  15. gauss = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
  16. cv2.THRESH_BINARY, 21, 15)
  17.  
  18. cv2.imshow('Binary', bin)
  19. cv2.imshow('Otsu', otsu)
  20. cv2.imshow('Triangle', tri)
  21. cv2.imshow('Adaptive', adapt)
  22. cv2.imshow('Gauss', gauss)
  23. cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement