2. Stunde - Übungen
1 from scipy import *
2 from pylab import *
3
4 def gaussian(center, width):
5 """Returns a gaussian function"""
6 center_y,center_x=float(center[0]),float(center[1])
7 width_y,width_x=float(width[0]),float(width[1])
8 return lambda y,x: exp(-(((center_y-y)/width_y)**2+((center_x-x)/width_x)**2)/2)
9
10
11 Y,X=200,200 # Scalars
12 RGB=empty((Y,X,3),float) # Array
13 D,I={ 'R':(0,0,0), 'G':(200,100,1), 'B':(00,200,2) },{} # Dictionaries
14 y, x = mgrid[0:Y,0:X]
15 figure(1)
16 clf()
17 for color in D.keys():
18 I[color] = gaussian(D[color][0:2], (100,100))(y, x)
19 RGB[:,:,D[color][2]]=I[color]
20 subplot(2,2,D[color][2]+1)
21 imshow(I[color],origin='lower')
22 title(color)
23 gray()
24 subplot(2,2,4)
25 imshow(RGB,origin='lower')
26 title('RGB')
27 show()
28 savefig('rgb.png',dpi=100)