def phi(entry): # Likelihood fonction A = MesFonctions.matrice_A(entry[0:size].reshape((NbLigne, NbColonne)), methode="3") x_ = ( floue.reshape(size) - MesFonctions.conv_matrices(A, entry[size:2 * size].reshape((NbLigne, NbColonne)), "vecteur", "coin")) likelihood = np.dot(np.dot(x_, C_noise_inv), x_.transpose()) # Regularization term image_ = entry[0:size] # /sum(sum(im)) PSF_ = entry[size:2 * size] # /sum(sum(PSF)) if regularization == "spectral": fy_ = np.fft(image_) y_ = 0 for i in range(0, size): y_ = y_ + i * i * abs(fy_[i]) * abs(fy_[i]) regularization_im = y_ fz_ = np.fft(PSF_) z_ = 0 for i in range(0, size): z_ = z_ + i * i * abs(fz_[i]) * abs(fz_[i]) regularization_PSF = z_ elif regularization == "Tikhonov": y_ = sum(image_ * image_) regularization_im = math.sqrt(y_) z_ = sum(PSF_ * PSF_) regularization_PSF = math.sqrt(z_) t_ = likelihood + regularization_im + regularization_PSF return t_
# import Kernel_Estimation_v6 as MonImage import opkpy_v3 # ----------------------------------------------------------------------------------- # Quelle image importe-t-on ? # --> "essaie" pour une simple image 9x9 # --> nom de l'image sinon ("test", "chat", etc) ImageImportee = "essaie" # ----------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------- # On importe une image if ImageImportee == "essaie": NbLigne, NbColonne, image_vraie, latent, kernel_vrai, kernel = MesFonctions.mon_image("create") floue = MesFonctions.conv(image_vraie, kernel_vrai) # else : # NbLigne, NbColonne, image_vraie, kernel_vrai, floue, kernel, inutile = MonImage.Ouverture("ImageImportee") # ----------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------- # On declare certains parametres size = NbLigne * NbColonne regularization = "Tikhonov" dt = 10 # On fait les conversions en vecteur floue_v = floue.reshape(size) kernel_v = kernel.reshape(size) # On cree la matrice bruit