''' Created on 14 avr. 2014 @author: vialard ''' import numpy as np import matplotlib.cm as cm def GoldenSearch(func,x,gradient,tol): alpha= (np.sqrt(5)-1)/2; a = 0. b= 0.5 iter = 0 #print "######## Golden start #########" while (func(x-gradient*a)<=func(x-gradient*b) and (iter<10)): b/=2. iter+=1 c = 2*b iter = 0 while np.abs(b-a)>tol: c = alpha*a + (1-alpha)*b d= a+b-c if func(x-gradient*c)niveau) def ArrangeMask(mask,shape): nx = shape[0] ny = shape[1] mask[1:nx,:] += mask[1:nx,:] mask[0:nx-1,:] += mask[1:nx,:] mask/=3.0 mask[:,1:ny]+= mask[:,0:ny-1] mask[:,0:ny-1]+= mask[:,1:ny] mask/=3.0 if __name__ == "__main__": mask = GenereMasque((512,512),1.9) import pylab as pl pl.imshow(mask, cmap = cm.Greys_r) pl.show()