-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeatureExtraction.py
More file actions
64 lines (52 loc) · 1.47 KB
/
Copy pathfeatureExtraction.py
File metadata and controls
64 lines (52 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 15 19:41:29 2020
@author: shield
"""
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 15 16:08:04 2020
@author: himanshu
"""
import numpy as np
import cv2
import glob
def featureExtraction(img_path, config):
x = list()
ksize = config['ksize']
sigma = config['sigma']
lambdaa = config['lambdaa']
gamma = config['gamma']
phi = 0
no_of_angles = config['no_of_angles']
img = cv2.imread(img_path,0)
for i in range(no_of_angles):
theta = i * (np.pi/no_of_angles)
kernel = cv2.getGaborKernel(ksize,sigma,theta,lambdaa,gamma,phi,ktype = cv2.CV_32F)
fimg = cv2.filter2D(img, cv2.CV_8UC3,kernel)
fimg = 255 - fimg
rsum = np.sum(fimg,axis=1)
rsum = (rsum/128)*10
x.append(rsum)
return np.array(x).ravel()
config = dict()
config['ksize'] = (13,13)
config['sigma'] = 10
config['lambdaa'] = 15
config['gamma'] = 0
config['no_of_angles'] = 8
img_path = "img/2bw.png"
X = list()
y = list()
count = 0
for path in glob.glob("/media/himanshu/C2B05102B050FDFB/dataset/exp/lines/**/*.png",recursive=True):
wid = path.split("/")[7]
x = featureExtraction(path, config)
X.append(x)
y.append(wid)
count+=1
print("count = ", count)
X = np.array(X)
y = np.array(y)
np.savez_compressed("/home/himanshu/Desktop/lines_all_gabor.npz",data = X, target = y)