-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheye1.py
90 lines (72 loc) · 2.14 KB
/
eye1.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
import cv2
import numpy as np
import matplotlib.pyplot as plt
# 500 x 250
img = cv2.imread('35_training.tif')
img[:,:,0] = 0
img[:,:,2] = 0
#cv2.imshow('original',img)
sobelx = cv2.Sobel(img,cv2.CV_32F,1,0,ksize=3)
sobely = cv2.Sobel(img,cv2.CV_32F,0,1,ksize=3)
sx = np.multiply(sobelx[:,:,1], sobelx[:,:,1])
sy = np.multiply(sobely[:,:,1], sobely[:,:,1])
sxy = np.multiply(sobelx[:,:,1], sobely[:,:,1])
phase=cv2.phase(sobelx,sobely,angleInDegrees=True)
mag = (sx + sy)
# sx = np.divide(sx, mag)
# sy = np.divide(sy, mag)
# sxy = np.divide(sxy, mag)
# sx = np.nan_to_num(sx, copy = False)
# sy = np.nan_to_num(sy, copy = False)
# sxy = np.nan_to_num(sxy, copy = False)
# old_err_state = np.seterr(divide='raise')
# ignored_states = np.seterr(**old_err_state)
w,h = mag.shape
min = np.min(mag)
max = np.max(mag)
mag = mag*255/max
st = np.zeros((w,h,2,2))
eigvalues=np.zeros((w,h,2))
eigvectors =np.zeros((w,h,2,2))
for i in range(w):
for j in range(h):
st[i,j,0,0] = sx[i,j]
st[i,j,0,1] = sxy[i,j]
st[i,j,1,0] = sxy[i,j]
st[i,j,1,1] = sy[i,j]
eigvalues[i,j],eigvectors[i,j] = np.linalg.eigh(st[i,j])
#
#extra = np.zeros((w,h))
#
#for i in range(w):
# for j in range(h):
#
# extra[i,j] = eigvalues[i,j,1]
#
#cv2.imshow('extra',extra)
#p = np.asarray(mag).astype('int8')
#w,h = mag.shape
#y, x = np.mgrid[0:h:500j, 0:w:500j]
#[dy, dx] = np.gradient(p)
#q = np.multiply(dx, dx) + np.multiply(dy, dy)
#cv2.imshow('q',q)
#plt.figure()
#plt.title('Arrows scale with plot width, not view')
#Q = plt.quiver(x[::3], y[::3], sx[::3], sy[::3], units='width')
#qk = plt.quiverkey(Q, 0.1, 0.1, 2, r'$2 \frac{m}{s}$', labelpos='E',
# coordinates='figure')
#[dy, dx] = np.gradient(p)
#skip = (slice(None, None, 3), slice(None, None, 3))
#
#fig, ax = plt.subplots()
#im = ax.imshow(dx, extent=[x.min(), x.max(), y.min(), y.max()])
#ax.quiver(x[skip], y[skip], dx[skip], dy[skip])
#
#ax.set(aspect=1, title='Quiver Plot')
#plt.show()
cv2.imshow('sobelx',sobelx)
cv2.imshow('sobely',sobely)
cv2.imshow('phase',phase)
cv2.imshow('mag',mag)
cv2.waitKey(0)
cv2.destroyAllWindows()