Last active
July 3, 2016 13:24
-
-
Save jikkenyametatta/43e45e3a1c0bd891b52cc476d04e63ba 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
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Jun 28 | |
@author: jyoshida@jikkenyametatta | |
opencv&numpy | |
""" | |
import cv2 | |
import numpy as np | |
if __name__ == '__main__': | |
filename = "neko.jpg" | |
img = cv2.imread(filename, cv2.CV_LOAD_IMAGE_GRAYSCALE) | |
# img = cv2.pyrDown(img) | |
img = cv2.Canny(img, 50, 200); | |
canvas = img.copy() | |
canvas64 = canvas.astype(np.float64) | |
dstmax = np.zeros(canvas.shape, np.float64) | |
meanvals = [] | |
for itheta in range(180): | |
print itheta, | |
kernel_size = 40 | |
sigma = 1 | |
theta = np.deg2rad(itheta) | |
lmbda = 2.0 | |
gamma = 0.06 | |
kernelc = cv2.getGaborKernel((kernel_size,kernel_size), sigma, theta, lmbda, gamma, 0); | |
kernels = cv2.getGaborKernel((kernel_size,kernel_size), sigma, theta, lmbda, gamma, np.deg2rad(-90)); | |
dstc = np.zeros_like(canvas64) | |
dsts = np.zeros_like(canvas64) | |
dstc = cv2.filter2D(canvas64, -1, kernelc); | |
dsts = cv2.filter2D(canvas64, -1, kernels); | |
dst = np.zeros_like(canvas64) | |
dst = cv2.add(dst, cv2.pow(dstc,2)) | |
dst = cv2.add(dst, cv2.pow(dsts,2)) | |
dst = cv2.sqrt(dst) | |
np.maximum(dst, dstmax, dstmax) | |
meanvals.append(dst.mean()) | |
#cv2.imshow('dstc', dstc) | |
#cv2.imshow('dsts', dsts) | |
#cv2.imshow('kernelc', kernelc) | |
#cv2.imshow('kernels', kernels) | |
#cv2.waitKey(0) | |
cv2.normalize(dstmax, dstmax, 0, 255, cv2.NORM_MINMAX) | |
dstmaxdisp = np.zeros(canvas.shape, np.uint8) | |
dstdisp = dstmax.astype(np.uint8) | |
#gaborimg = cv2.pyrDown(dstdisp) | |
#cv2.imwrite('{0}_gaborimg.png'.format(filename), dstdisp) | |
cv2.imshow('dstdisp', dstdisp) | |
cv2.imshow('img', img) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment