-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage_creation_dot_7_8.py
107 lines (87 loc) · 3.44 KB
/
image_creation_dot_7_8.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
import numpy as np
import matplotlib.pyplot as plt
import cv2
from microsaccades_functions import *
import sys
import os
#---------------------------------------------------------------------------------------IMAGE-CREATION
image_size = 300
radius = 4. #dot size of 4arcmin -> 8px
rect_size = 110. #size of inner radius
vel = 0.06 #velocity is 30 arcmin/s -> 60px/1000ms
suff = sys.argv[1]
vel_on = int(sys.argv[2])
angle = sys.argv[3]
rem_on = int(sys.argv[4])
rect = int(sys.argv[5])
cem_on = int(sys.argv[6])
cem_l_on = int(sys.argv[7])
direction = float(angle)*np.pi/8. #dot moving direction in arc (get right velocities !)
#for normal distributed microsaccades
sigma = 0.447
file_location = "/home/schrader/Documents/microsaccades/video/img_input/poletti2010/"+str(suff)
#if vel_on==1:
# file_location += "/"+str(angle)+"_8_pi_arc"
#save the different conditions
film_length = 1000 #int(framerate)*(stripe_width+gap)
#get normal 2d distribution
mean = [0, 0]
cov = [[1, 0], [0, 1]]
tl_x, tl_y = sigma*np.random.multivariate_normal(mean, cov, film_length).T
d_data = open(str(file_location)+'/displacement.data','w+')
np.save(d_data, (tl_x, tl_y))
d_data.close()
pos = (image_size/2.+0.5,image_size/2+0.5)
center = (image_size/2.-0.5,image_size/2.-0.5) #for rectangle
#loop through the
for f in range(film_length):
canvas = np.zeros((image_size, image_size))
#update position
#for dot moving task-----------------------
if vel_on==1:
pos = (pos[0]+vel*np.sin(direction),pos[1]+vel*np.cos(direction))
#------------------------------------------
#for random eye movements------------------
if rem_on==1:
pos = (pos[0]+tl_y[f],pos[1]+tl_x[f])
#------------------------------------------
#for moving rectangle frame----------------
if cem_l_on==1:
center = (center[0]+vel*np.sin(direction),center[1]+vel*np.cos(direction))
#------------------------------------------
#for randomly moving rectangle frame-------
if cem_on==1:
center = (center[0]+tl_y[f],center[1]+tl_x[f])
#------------------------------------------
for i in range(image_size):
for j in range(image_size):
dist = np.sqrt((float(i)-pos[0])*(float(i)-pos[0])+(float(j)-pos[1])*(float(j)-pos[1]))
if dist <= 3.5:
canvas[i,j] = 1
elif 3.5 < dist and dist < 4.5:
canvas[i,j] = 4.5 - dist
#rectangle-(exp2)--------------------------
if rect==1:
if abs(float(i)-center[0]) > rect_size or abs(float(j)-center[1])> rect_size:
canvas[i,j] = 1
#------------------------------------------
fig = plt.figure()
fig.set_size_inches(2,2)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(canvas, cmap='gray')
plt.savefig(file_location + "/first"+str(f+1).zfill(3)+".png", dpi = 140)
plt.close()
#--------------------------------------------------------------------------------GAUSSIAN-BLURRING
img = cv2.imread(file_location + "/first"+str(f+1).zfill(3)+".png",0)
rows,cols = img.shape
blur = cv2.GaussianBlur(img,(3,3),0.5)
fig = plt.figure()
fig.set_size_inches(2,2)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(blur, cmap='gray')
plt.savefig(file_location + "/second"+str(f+1).zfill(3)+".png", dpi = 140)
plt.close()