From 63d7218f085c8934902d9b09feb2fa5a875fc6c7 Mon Sep 17 00:00:00 2001 From: Ludovic CASTIGLIA Date: Sun, 9 Feb 2025 19:50:26 +0100 Subject: [PATCH] commentaire --- function.py | 46 +++++++++++++++++++------------------- nnf.py => imageRelation.py | 32 +++++++++++++------------- 2 files changed, 40 insertions(+), 38 deletions(-) rename nnf.py => imageRelation.py (83%) diff --git a/function.py b/function.py index a44d4ab..0f6f7a4 100644 --- a/function.py +++ b/function.py @@ -1,10 +1,10 @@ from maskedImage import MaskedImage import matplotlib.pyplot as plt -from nnf import Nnf +import concurrent.futures +from imageRelation import ImageRelation import numpy as np import cv2 -import concurrent.futures def read(file): # fonction qui renvoit une image à partir de son chemin @@ -19,7 +19,7 @@ def doTheInpainting(img,mask,radius): def maximizeForTheScale(scale): # fonction interne qui effectue l'impainting pour une version réduite de l'image iterEM = 1+2*scale - iterNnf = min(7,1+scale) + npPass = min(7,1+scale) source = sourceToTarget.input target = targetToSource.output newTarget = None @@ -34,7 +34,7 @@ def doTheInpainting(img,mask,radius): if not source.containsMask(x,y,radius): targetToSource.field[y,x] = (x,y,0) # on cherche les patchs - targetToSource.minimize(iterNnf) + targetToSource.findBestPatch(npPass) # on crée la source et la target upscaled = False if scale>=1 and emloop == iterEM: @@ -67,45 +67,45 @@ def doTheInpainting(img,mask,radius): if (level == maxLevel-1): target = source.copy() target.mask[0:target.height,0:target.width] = False - sourceToTarget = Nnf(source,target,radius) + sourceToTarget = ImageRelation(source,target,radius) sourceToTarget.randomize() - targetToSource = Nnf(target,source,radius) + targetToSource = ImageRelation(target,source,radius) targetToSource.randomize() else: - newNnf = Nnf(source,target,radius) - newNnf.initializeFromNnf(sourceToTarget) - sourceToTarget = newNnf + newImRel = ImageRelation(source,target,radius) + newImRel.initializeFromImageRelation(sourceToTarget) + sourceToTarget = newImRel - newNnfRev = Nnf(target,source,radius) - newNnfRev.initializeFromNnf(targetToSource) - targetToSource = newNnfRev + newImRelRev = ImageRelation(target,source,radius) + newImRelRev.initializeFromImageRelation(targetToSource) + targetToSource = newImRelRev target, sourceToTarget, targetToSource = maximizeForTheScale(level) plt.imshow(target.image) plt.pause(0.01) return target.image -def ExpectationStep(nnf, vote, source, upscale): +def ExpectationStep(imRel, vote, source, upscale): def ExpectationStepForNb(nb): # ajoute au vote pour toutes les pixels les valeurs déterminé lors de la recherche des patchs - wid = nnf.input.width//7 - for y in range(nnf.input.height): - for x in range(nb*wid,(nb+1)*wid if nb != 7 else nnf.input.width): # divise par 8 l'image dans la largeur pour calculer ses 8 parties en même temps grâce aux threads - xp, yp, dp = nnf.field[y,x] + wid = imRel.input.width//7 + for y in range(imRel.input.height): + for x in range(nb*wid,(nb+1)*wid if nb != 7 else imRel.input.width): # divise par 8 l'image dans la largeur pour calculer ses 8 parties en même temps grâce aux threads + xp, yp, dp = imRel.field[y,x] w = MaskedImage.similarity[dp] - for dy in range(-nnf.patchSize,nnf.patchSize): # pour toutes les pixels du patch qui ne sorte pas de l'image + for dy in range(-imRel.patchSize,imRel.patchSize): # pour toutes les pixels du patch qui ne sorte pas de l'image ys = yp+dy - if not 0<=ys0): - self.minimizeLink(x,y,i) + self.findBestPatchFroOne(x,y,i) for y in range(self.input.height-1,0,-1): # on cherche le meilleur patche en haut et à gauche for x in range(self.input.width-1,0,-1): if (self.field[y,x,2]>0): - self.minimizeLink(x,y,-i) + self.findBestPatchFroOne(x,y,-i) - def minimizeLink(self,x,y,direction): + def findBestPatchFroOne(self,x,y,direction): + # recherche le meilleur patch pour une zone en particulier dans un sens (en haut et à gauche | à droite et en bas) + cherche random # horizontale if (0