forked from Shikhargupta/Spiking-Neural-Network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recep_field.py
52 lines (42 loc) · 1.32 KB
/
recep_field.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
####################################################### README #########################################################
# This file consists of function that convolves an image with a receptive field so that input to the network is
# close to the form perceived by our eyes.
#########################################################################################################################
import numpy as np
import cv2
from parameters import param as par
def rf(inp):
sca1 = 0.625
sca2 = 0.125
sca3 = -0.125
sca4 = -.5
#Receptive field kernel
w = [[ sca4 ,sca3 , sca2 ,sca3 ,sca4],
[ sca3 ,sca2 , sca1 ,sca2 ,sca3],
[ sca2 ,sca1 , 1 ,sca1 ,sca2],
[ sca3 ,sca2 , sca1 ,sca2 ,sca3],
[ sca4 ,sca3 , sca2 ,sca3 ,sca4]]
pot = np.zeros([par.pixel_x,par.pixel_x])
ran = [-2,-1,0,1,2]
ox = 2
oy = 2
#Convolution
for i in range(par.pixel_x):
for j in range(par.pixel_x):
summ = 0
for m in ran:
for n in ran:
if (i+m)>=0 and (i+m)<=par.pixel_x-1 and (j+n)>=0 and (j+n)<=par.pixel_x-1:
summ = summ + w[ox+m][oy+n]*inp[i+m][j+n]/255
pot[i][j] = summ
return pot
if __name__ == '__main__':
img = cv2.imread("mnist1/" + str(1) + ".png", 0)
pot = rf(img)
max_a = []
min_a = []
for i in pot:
max_a.append(max(i))
min_a.append(min(i))
print "max", max(max_a)
print "min", min(min_a)