LehreWiki

   1 from scipy import empty,mgrid,exp,arange
   2 from pylab import figure,clf,subplot,imshow,title,gray,plot,show,savefig
   3 from string import *
   4 
   5 def gaussian(center, width):
   6         """Returns a gaussian function"""
   7         center_y,center_x=float(center[0]),float(center[1])
   8         width_y,width_x=float(width[0]),float(width[1])
   9         return lambda y,x: exp(-(((center_y-y)/width_y)**2+((center_x-x)/width_x)**2)/2)
  10 
  11 Y,X=200,200
  12 RGB=empty((Y,X,3),float)
  13 D,J,K={ 'R':(0,0,0), 'G':(200,100,1), 'B':(0,200,2) },{},{}
  14 x1,y1=arange(X),100
  15 x2,y2=100,arange(Y)
  16 figure(1)
  17 for color in D.keys():
  18         J[color] = gaussian(D[color][0:2], (100,100)) (y1,x1)
  19         RGB[:,:,D[color][2]]=J[color]
  20         plotcol=lower(color)
  21         plot(x1,J[color],plotcol)
  22 title('Schnitte durch y=100')
  23 figure(2)
  24 for color in D.keys():
  25         K[color] = gaussian(D[color][0:2], (100,100)) (y2,x2)
  26         RGB[:,:,D[color][2]]=K[color]
  27         plotcol=lower(color)
  28         plot(y2,K[color],plotcol)
  29 title('Schnitte durch x=100')
  30 show()

x_Schnitt.png y_Schnitt.png

LehreWiki: SiaExercisesLesson2LoesungDatenstrukturenB (last edited 2008-04-21 13:57:54 by NinaMaass)