Created
December 13, 2017 14:02
-
-
Save kavinvin/b99cfb1f04652a45a3e6f18d344b6bc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
from utils.transform import scale_img | |
def get_files(): | |
return ('{}.jpg'.format(n) for n in range(1, 20)) | |
def get_images(): | |
return (cv2.imread(file, cv2.IMREAD_GRAYSCALE) for file in get_files()) | |
def morph_dilate(image): | |
kernel = np.ones((1, 200), np.uint8) | |
return cv2.dilate(image, kernel) | |
def morph_erode(image): | |
kernel = np.ones((1, 100), np.uint8) | |
return cv2.erode(image, kernel) | |
def morph_close(image): | |
kernel = np.ones((10, 10), np.uint8) | |
return cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel) | |
def morph_open(image): | |
kernel = np.ones((10, 10), np.uint8) | |
return cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel) | |
def show(name, image): | |
cv2.imshow(name, scale_img(1000)(image)) | |
def smooth(image): | |
kernel = np.ones((15, 15), np.float32) / 225 | |
return cv2.filter2D(image, -1, kernel) | |
if __name__ == '__main__': | |
for file in get_files(): | |
img = cv2.imread('images/' + file, cv2.IMREAD_GRAYSCALE) | |
retval, threshold = cv2.threshold(img, 65, 255, cv2.THRESH_BINARY_INV) | |
transformed = morph_open(morph_dilate(threshold)) | |
cv2.imwrite('threshold/' + file, transformed) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment