-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage_creation_spatfreq.py
69 lines (59 loc) · 2.5 KB
/
image_creation_spatfreq.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
#!/bin/python
import sys
import os
import numpy as np
import matplotlib.pyplot as plt
import cv2
from microsaccades_functions import *
#---------------------------------------------------------------------------------------IMAGE-CREATION
#this is to test the responsibility to spatial frequencies
#grate reversing frequency (temporal) 2Hz -> 250ms for one return resp. 50 frames, framerate = 200/s
freq = sys.argv[1]
half_wl = 120./(float(freq))
stripe_width = int(half_wl)
gap = int(half_wl)
image_width = 120 #240 # two times because of rotation
image_height = 30
degrees = sys.argv[1]
file_location = "video/img_input/spatfreq_0fr0deg" + str(freq) + "spat"
film_length = 400 #2 seconds
c=[]
even = False
offset = int(half_wl)
#maybe here a loop to make it last even longer
for f in range(film_length):
#if f%framerate == 0 and f>0: #not yet
# offset += 1
canvas = np.zeros((image_height, image_width))
canvas[0,0]=1
canvas[:,:] = 0.5*np.cos(float(f)/100.*np.pi-np.pi)+0.5
current_col = int(offset) #there's the problem
if offset < 0:
canvas[:, 0:current_col+stripe_width] = 0.5*np.cos(float(f)/100.*np.pi)+0.5
#canvas[:, current_col+stripe_width] = (f%int(framerate))/framerate
current_col += stripe_width + gap
while current_col < image_width:
if current_col + stripe_width + gap <= image_width-1:
canvas[:, current_col:current_col+stripe_width] = 0.5*np.cos(float(f)/100.*np.pi)+0.5
#canvas[:, current_col] = 1 - (f%int(framerate))/framerate
#canvas[:, current_col+stripe_width] = (f%int(framerate))/framerate
current_col += stripe_width + gap
elif current_col + stripe_width <= image_width-1:
canvas[:, current_col:current_col+stripe_width] = 0.5*np.cos(float(f)/100.*np.pi)+0.5
#canvas[:, current_col] = 1 - (f%int(framerate))/framerate
#canvas[:, current_col+stripe_width] = (f%int(framerate))/framerate
current_col = image_width
else:
#canvas[:, current_col] = 1 - (f%int(framerate))/framerate
canvas[:, current_col:] = 0.5*np.cos(float(f)/100.*np.pi)+0.5
current_col = image_width
if f==30:
print canvas
fig = plt.figure()
fig.set_size_inches(1,0.25)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(canvas, cmap='gray', vmin=0., vmax=1.)
plt.savefig(file_location + "/second"+str(f+1).zfill(3)+".png", dpi = 120)
plt.close()