Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- gray = cv2.imread('D:\PT\pic\pcg.jpg', cv2.IMREAD_GRAYSCALE)
- scalex = 0.5
- scaley = 0.5
- X, Y = gray.shape[1]*scalex, gray.shape[0]*scaley
- gray = cv2.resize(gray, (int(X), int(Y)))
- binary_thresh, bin = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)
- Otsu_thresh, otsu = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU)
- triangle_thresh, tri = cv2.threshold(gray, 0, 255, cv2.THRESH_TRIANGLE)
- adapt = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
- cv2.THRESH_BINARY, 13, 15)
- gauss = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
- cv2.THRESH_BINARY, 21, 15)
- cv2.imshow('Binary', bin)
- cv2.imshow('Otsu', otsu)
- cv2.imshow('Triangle', tri)
- cv2.imshow('Adaptive', adapt)
- cv2.imshow('Gauss', gauss)
- cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement