|
a |
|
b/Gabor_HistEq.py |
|
|
1 |
#%% #this line is for VSCode editor only |
|
|
2 |
import cv2 |
|
|
3 |
#from skimage.measure import compare_ssim |
|
|
4 |
import argparse |
|
|
5 |
#import imutils |
|
|
6 |
import numpy as np |
|
|
7 |
import matplotlib.pyplot as plt |
|
|
8 |
%matplotlib inline |
|
|
9 |
#change the path as per you configuration |
|
|
10 |
|
|
|
11 |
img = cv2.imread(r'C:\\Users\\ANSHUL KIYAWAT\\Desktop\\image3.jpg',0) |
|
|
12 |
|
|
|
13 |
|
|
|
14 |
#sobely = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=5) |
|
|
15 |
#sobelx = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=5) |
|
|
16 |
#laplacian = cv2.Laplacian(img,cv2.CV_64F) |
|
|
17 |
|
|
|
18 |
def build_filters(): |
|
|
19 |
""" returns a list of kernels in several orientations |
|
|
20 |
""" |
|
|
21 |
filters = [] |
|
|
22 |
ksize = 31 |
|
|
23 |
for theta in np.arange(0, np.pi, np.pi / 32): |
|
|
24 |
params = {'ksize': (ksize, ksize), 'sigma': 2.5, 'theta': theta, 'lambd': 15.0, |
|
|
25 |
'gamma': 0.02, 'psi': 0, 'ktype': cv2.CV_32F} |
|
|
26 |
|
|
|
27 |
kern = cv2.getGaborKernel(**params) |
|
|
28 |
kern /= 1.5*kern.sum() |
|
|
29 |
filters.append((kern, params)) |
|
|
30 |
return filters |
|
|
31 |
|
|
|
32 |
|
|
|
33 |
def process(img, filters): |
|
|
34 |
""" returns the img filtered by the filter list |
|
|
35 |
""" |
|
|
36 |
accum = np.zeros_like(img) |
|
|
37 |
for kern, params in filters: |
|
|
38 |
fimg = cv2.filter2D(img, cv2.CV_8UC3, kern) |
|
|
39 |
np.maximum(accum, fimg, accum) |
|
|
40 |
return accum |
|
|
41 |
|
|
|
42 |
|
|
|
43 |
#main |
|
|
44 |
filters = build_filters() |
|
|
45 |
p = process(img, filters) |
|
|
46 |
|
|
|
47 |
equ = cv2.equalizeHist(p) |
|
|
48 |
|
|
|
49 |
plt.figure(1) |
|
|
50 |
plt.subplot(121), plt.imshow(img, cmap='gray') |
|
|
51 |
plt.title('Original'), plt.xticks([]), plt.yticks([]) |
|
|
52 |
|
|
|
53 |
plt.subplot(122), plt.imshow(equ, cmap='gray') |
|
|
54 |
plt.title('Gabor Only'),plt.xticks([]),plt.yticks([]) |
|
|
55 |
|
|
|
56 |
#plt.subplot(123), plt.imshow(equ, cmap='gray') |
|
|
57 |
#plt.title('Histogram + Gabor'), plt.xticks([]), plt.yticks([]) |