Last active
April 11, 2016 22:22
-
-
Save parthpower/78ba2aeedd403a2cab720625733179ff to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from sys import argv | |
import numpy as np | |
import cv2 | |
if len(argv)!=5: | |
print("Usage: %s <height> <width> <input TXT File> <output TXT File>"%(argv[0])) | |
exit() | |
COL=int(argv[1]) | |
ROW=int(argv[2]) | |
IN_FILE_PATH = argv[3] | |
OUT_FILE_PATH = argv[4] | |
kernel_y = np.array([[-1,-2,-1],[0,0,0],[1,2,1]]) | |
kernel_x = np.array([[-1,0,1],[-2,0,2],[-1,0,1]]) | |
with open(IN_FILE_PATH,'r') as inFile: | |
sample = np.array([[int(next(inFile)) for each in range(COL)] for a in range(ROW)],np.uint8) | |
print(sample) | |
CONVOLVED_x = np.zeros((1,ROW*COL)) | |
CONVOLVED_x = cv2.filter2D(sample,cv2.CV_8U,kernel_x).reshape((1,ROW*COL)) | |
CONVOLVED_y = np.zeros((1,ROW*COL)) | |
CONVOLVED_y = cv2.filter2D(sample,cv2.CV_8U,kernel_y).reshape((1,ROW*COL)) | |
CONVOLVED = CONVOLVED_x + CONVOLVED_y | |
with open(OUT_FILE_PATH,'w') as outFile: | |
outFile.writelines([str(each)+'\n' for each in CONVOLVED[0]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment