-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetHOG.py
116 lines (85 loc) · 2.54 KB
/
getHOG.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import cv2
import numpy as np
from PIL import Image
import pdb
from scipy import ndimage
import numpy as np
import math
import cv2
def subimage(image, center, theta, width, height):
shape = image.shape[:2]
matrix = cv2.getRotationMatrix2D( center=center, angle=theta, scale=1 )
image = cv2.warpAffine( src=image, M=matrix, dsize=shape )
x = int( center[0] - width/2 )
y = int( center[1] - height/2 )
image = image[ y:y+height, x:x+width ]
return image
hog = cv2.HOGDescriptor()
im = cv2.imread("/Users/sachin007/Desktop/pix2pix_train/sym_test/images/joined/testd33-joined.png")
row,col,chan = np.shape(im)
min_j = 1000;
max_j = 0;
i = 100
for j in range(100,140):
if (np.all(im[128,j,:])==np.all((0,0,1))):
print(j)
if (j<min_j):
min_j = j
if(j>max_j):
max_j = j
mid_j = int((min_j+max_j)/2) + 50
#take a 20 20 patch near the symmetry axis
patch1 = im[i-25:i+25,mid_j-50:mid_j,:]
patch2 = im[i-25:i+25,mid_j:mid_j+50,:]
# print(np.shape(patch1))
# cv2.imshow('Image1',patch1)
# cv2.imshow('Image2',patch2)
# patch1 = Image.fromarray(patch1, 'RGB')
# patch2 = Image.fromarray(patch2, 'RGB')
# cv2.imwrite("patch1.png",patch1)
# cv2.imwrite("patch2.png",patch2)
# p1 = cv2.imread("patch1.png")
# p2 = cv2.imread("patch2.png")
# orb = cv2.ORB_create()
# # sift = cv2.SIFT()
# im_cropped = im[10:50,10:50,:]
# kp, des = orb.detectAndCompute(im_cropped,None)
#calculating the correlation
sigma1 = np.var(patch1)
sigma2 = np.var(patch2)
mean1 = np.mean(patch1)
mean2 = np.mean(patch2)
row,col,chan = np.shape(patch1)
corr=0.0
for m in range(row):
for n in range(col):
for k in range(3):
corr = corr + (patch1[m,n,k]-mean1)*(patch2[m,col-n-1,k] - mean2)
corr = corr/(3*sigma1*sigma2)
print(corr)
self_corr=0.0
for m in range(row):
for n in range(col):
for k in range(3):
self_corr = self_corr + (patch1[m,n,k]-mean1)*(patch1[m,n,k] - mean1)
self_corr = self_corr/(3*sigma1*sigma1)
print(self_corr)
print("ratio",corr/self_corr)
# gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
# edges = cv2.Canny(gray,50,150,apertureSize = 3)
# lines = cv2.HoughLines(edges,1,np.pi/180,200)
# for rho,theta in lines[0]:
# a = np.cos(theta)
# b = np.sin(theta)
# x0 = a*rho
# y0 = b*rho
# x1 = int(x0 + 1000*(-b))
# y1 = int(y0 + 1000*(a))
# x2 = int(x0 - 1000*(-b))
# y2 = int(y0 - 1000*(a))
# cv2.line(im,(x1,y1),(x2,y2),(0,0,255),2)
# cv2.imwrite('houghlines.jpg',im)
image = subimage(im, center=(128, 128), theta=-90, width=50, height=50)
cv2.imwrite('patch.jpg', image)
# pdb.set_trace()
# cv2.waitKey(0)