-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_processing.py
More file actions
71 lines (56 loc) · 1.69 KB
/
image_processing.py
File metadata and controls
71 lines (56 loc) · 1.69 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
65
66
67
68
69
70
71
import numpy as np
import sys
import cv2
import os
import time
rcycles = 14;
tcycles = 12;
stimSize = 250;
xylim = 2 * np.pi* rcycles;
freq=3;
numFrames=120/freq;
#color variable
white = 200
grey = 100
black = 0
D=10
L=20
def getFrame(n):
#Generate next frame of simulation as numpy array
if getFrame.z is None:
#for the meshgrid
x2, y2 = np.meshgrid(np.linspace(-xylim,xylim,stimSize-1), np.linspace(-xylim,xylim,stimSize-1))
#x2, y2 = np.meshgrid(np.linspace(-xylim,xylim,(0.5*xylim/(stimSize-1))), np.linspace(-xylim,xylim,0.5*xylim/(stimSize-1)))
#Get the value of the pixel function
#t0 = time.time()
getFrame.z = circularCheckerBoard(x2, y2,n)
#t1 = time.time()
#print(t1 - t0, "seconds wall time\n")
return getFrame.z
def sin2d(x,y):
return np.sin(x) + np.cos(y)
def circularCheckerBoard(x1,y1,n):
#based on matlab code
sql = xylim**2
at = np.arctan2(x1,y1)
xylim1 = x1
phiAngle=(np.pi/2)+(np.pi/2)*np.sin((2*np.pi*n*(freq/(2*60)))-(np.pi/2))
checks = np.sign(np.cos(np.pi*np.sqrt(x1**2 + y1**2)/D+phiAngle*(L/D))*np.cos(at*tcycles))
circle = ((x1**2 + y1**2) <= xylim**2)*1
checks = checks* circle
#print(circle)
return checks
getFrame.z = None
t0 = time.time()
for i in range(1,600):
# Get a numpy array to display from the simulation
getFrame.z = None
npimage=getFrame(i)
cv2.imshow('image',npimage)
#cv2.waitKey(round(1000/60))
cv2.waitKey(1)
time.sleep(1./60)
t1 = time.time()
print(t1 - t0, "seconds wall time\n")
import os
os._exit(1)