Skip to content

Instantly share code, notes, and snippets.

@simondegheselle
Created March 26, 2019 13:11
Show Gist options
  • Save simondegheselle/64e4c7d3003aae63d2ea012058e6e24e to your computer and use it in GitHub Desktop.
Save simondegheselle/64e4c7d3003aae63d2ea012058e6e24e to your computer and use it in GitHub Desktop.
import numpy as np
import cv2
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-f", help="path to image", dest="filename", required=True)
args = parser.parse_args()
img = cv2.imread(args.filename)
dim = 90
kernel = cv2.getGaussianKernel(ksize=dim,sigma=30)
squareMatrix = np.zeros((dim,dim),dtype=float)
for i in range(dim):
squareMatrix[i][dim//2] = kernel[i]
kernel2= cv2.getGaussianKernel(ksize=dim,sigma=3)
them = cv2.filter2D(squareMatrix,-1,kernel2.T)
derivedThem = cv2.Sobel(them, -1, 1, 0)
rows,cols,ch = img.shape
rotationMatrix = cv2.getRotationMatrix2D((dim/2 , dim/2), 150, 1)
dog = cv2.warpAffine(derivedThem, rotationMatrix, (dim,dim))
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
img = np.abs(cv2.filter2D(img,cv2.CV_32F,dog))
minV, maxV, minL, maxL = cv2.minMaxLoc(dog)
for i in range(dim):
for j in range (dim):
dog[i][j] = dog[i][j]/maxV
dog[i][j] = dog[i][j]/2
dog[i][j] = dog[i][j] + 0.5
minV, maxV, minL, maxL = cv2.minMaxLoc(img)
cv2.namedWindow("output", cv2.WINDOW_NORMAL)
cv2.resizeWindow("output", 3200, 1200)
cv2.imshow('output', dog)
cv2.waitKey(0)
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment