def fg(x, gx): legradient = grad_dt(x) gx[0:size] = legradient[0:size] gx[size:2 * size] = legradient[size:2 * size] return phi(x) ###################### FONCTION DE DEFLOUTAGE D'IMAGE ######################## # On definit notre premier point x (ici l'image floue et un kernel quelconque) x = np.concatenate((image, psf), axis=0) g = np.zeros(2*size) f = np.array([fg(x,g)], dtype="double") print "f initial = ", f # On execute la fonction de minimisation x_out = opkpy_v3.opk_minimize(x, fg, g, algorithm="vmlmb", linesearch="cubic", vmlmb="lbfgs", limited=0, maxeval=200, maxiter = 200) objet_defloute = x_out[0:size].reshape((NbLigne,NbColonne)) kernel_defloute = x_out[size:2*size].reshape((NbLigne,NbColonne)) image_out = np.real(np.fft.ifft(np.fft.fft(x_out[0:size]) * np.fft.fft(np.roll(x_out[size:2*size]/sum(x_out[size:2*size]),np.round((size+1)/2))))).reshape((NbLigne,NbColonne)) # objets matshow(image_mat,cmap=cm.gray) # point de depart matshow(objet_mat,cmap=cm.gray) # objectif matshow(objet_defloute,cmap=cm.gray) # resultat # psf matshow(psf_mat,cmap=cm.gray) matshow(kernel_mat,cmap=cm.gray) matshow(kernel_defloute,cmap=cm.gray)
# nlcg="PolakRibierePolyak", limited=1) #print"PolakRibierePolyak :" + str(x_out) + "\n \n" #x_out = opkpy_v3.opk_minimize(x, fg_Rosen, g, algorithm="nlcg", linesearch="nonmonotone", # nlcg="Fletcher", limited=1) #print"Fletcher :" + str(x_out) + "\n \n" #x_out = opkpy_v3.opk_minimize(x, fg_Rosen, g, algorithm="nlcg", linesearch="nonmonotone", # nlcg="LiuStorey", limited=1) #print"LiuStorey :" + str(x_out) + "\n \n" #x_out = opkpy_v3.opk_minimize(x, fg_Rosen, g, algorithm="nlcg", linesearch="nonmonotone", # nlcg="DaiYuan", limited=1) #print"DaiYuan :" + str(x_out) + "\n \n" #x_out = opkpy_v3.opk_minimize(x, fg_Rosen, g, algorithm="nlcg", linesearch="nonmonotone", # nlcg="PerryShanno", limited=1) #print"PerryShanno :" + str(x_out) + "\n \n" x_out = opkpy_v3.opk_minimize(x, fg_Rosen, g, algorithm="vmlmb", linesearch="nonmonotone", nlcg="HagerZhang", limited=0) print("HagerZhang :" + str(x_out) + "\n \n") ############################################################################## ################################# PARAMETRES ################################# # x, f, g # bl, bu ---> only for vmlmb ###### algorithm ###### linesearch # autostep ###### nlcg ---> only for nlcg ###### vmlmb ---> only for vmlmb # delta, epsilon