|
|
@ -9,10 +9,11 @@ class Nnf:
|
|
|
|
self.patchSize = patchSize
|
|
|
|
self.patchSize = patchSize
|
|
|
|
|
|
|
|
|
|
|
|
def randomize(self):
|
|
|
|
def randomize(self):
|
|
|
|
|
|
|
|
|
|
|
|
self.field = np.zeros((self.input.height, self.input.width, 3), dtype=int)
|
|
|
|
self.field = np.zeros((self.input.height, self.input.width, 3), dtype=int)
|
|
|
|
for x in range(self.input.width):
|
|
|
|
self.field[:,:,2] += MaskedImage.DSCALE
|
|
|
|
for y in range(self.input.height):
|
|
|
|
self.field[:,:,0] = np.random.randint(0,self.output.width,self.input.width)
|
|
|
|
self.field[y,x] = (random.randint(0,self.output.width),random.randint(0,self.output.height),MaskedImage.DSCALE)
|
|
|
|
self.field[:,:,1] = np.random.randint(0,self.output.height,self.input.height)
|
|
|
|
self.initialize()
|
|
|
|
self.initialize()
|
|
|
|
|
|
|
|
|
|
|
|
def initializeFromNnf(self,nnf):
|
|
|
|
def initializeFromNnf(self,nnf):
|
|
|
@ -30,8 +31,8 @@ class Nnf:
|
|
|
|
for y in range(self.input.height):
|
|
|
|
for y in range(self.input.height):
|
|
|
|
for x in range(self.input.width):
|
|
|
|
for x in range(self.input.width):
|
|
|
|
self.field[y,x,2] = self.distance(x,y,self.field[y,x,0],self.field[y,x,1])
|
|
|
|
self.field[y,x,2] = self.distance(x,y,self.field[y,x,0],self.field[y,x,1])
|
|
|
|
iter=0
|
|
|
|
iter= 0
|
|
|
|
maxIter =10
|
|
|
|
maxIter = 10
|
|
|
|
while (self.field[y,x,2] == MaskedImage.DSCALE and iter<maxIter):
|
|
|
|
while (self.field[y,x,2] == MaskedImage.DSCALE and iter<maxIter):
|
|
|
|
self.field[y,x] = (random.randint(0,self.output.width),random.randint(0,self.output.height),self.distance(x,y,self.field[y,x,0],self.field[y,x,1]))
|
|
|
|
self.field[y,x] = (random.randint(0,self.output.width),random.randint(0,self.output.height),self.distance(x,y,self.field[y,x,0],self.field[y,x,1]))
|
|
|
|
iter += 1
|
|
|
|
iter += 1
|
|
|
@ -54,9 +55,7 @@ class Nnf:
|
|
|
|
yp = self.field[y,x-direction,1]
|
|
|
|
yp = self.field[y,x-direction,1]
|
|
|
|
dp = self.distance(x,y,xp,yp)
|
|
|
|
dp = self.distance(x,y,xp,yp)
|
|
|
|
if (dp<self.field[y,x,2]):
|
|
|
|
if (dp<self.field[y,x,2]):
|
|
|
|
self.field[y,x,0] = xp
|
|
|
|
self.field[y,x] = (xp,yp,dp)
|
|
|
|
self.field[y,x,1] = yp
|
|
|
|
|
|
|
|
self.field[y,x,2] = dp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# verticale
|
|
|
|
# verticale
|
|
|
|
if (0<y-direction<self.input.height):
|
|
|
|
if (0<y-direction<self.input.height):
|
|
|
@ -64,9 +63,7 @@ class Nnf:
|
|
|
|
yp = self.field[y-direction,x,1] + direction
|
|
|
|
yp = self.field[y-direction,x,1] + direction
|
|
|
|
dp = self.distance(x,y,xp,yp)
|
|
|
|
dp = self.distance(x,y,xp,yp)
|
|
|
|
if (dp<self.field[y,x,2]):
|
|
|
|
if (dp<self.field[y,x,2]):
|
|
|
|
self.field[y,x,0] = xp
|
|
|
|
self.field[y,x] = (xp,yp,dp)
|
|
|
|
self.field[y,x,1] = yp
|
|
|
|
|
|
|
|
self.field[y,x,2] = dp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# recherche random
|
|
|
|
# recherche random
|
|
|
|
zoneRecherche = max(self.output.height,self.output.width)
|
|
|
|
zoneRecherche = max(self.output.height,self.output.width)
|
|
|
@ -77,15 +74,12 @@ class Nnf:
|
|
|
|
yp = max(0,min(self.output.height-1,yp))
|
|
|
|
yp = max(0,min(self.output.height-1,yp))
|
|
|
|
dp = self.distance(x,y,xp,yp)
|
|
|
|
dp = self.distance(x,y,xp,yp)
|
|
|
|
if (dp<self.field[y,x,2]):
|
|
|
|
if (dp<self.field[y,x,2]):
|
|
|
|
self.field[y,x,0] = xp
|
|
|
|
self.field[y,x] = (xp,yp,dp)
|
|
|
|
self.field[y,x,1] = yp
|
|
|
|
|
|
|
|
self.field[y,x,2] = dp
|
|
|
|
|
|
|
|
zoneRecherche = int(zoneRecherche/2)
|
|
|
|
zoneRecherche = int(zoneRecherche/2)
|
|
|
|
|
|
|
|
|
|
|
|
def distance(self,x,y,xp,yp):
|
|
|
|
def distance(self,x,y,xp,yp):
|
|
|
|
return distance(self.input,x,y,self.output,xp,yp,self.patchSize)
|
|
|
|
return distance(self.input,x,y,self.output,xp,yp,self.patchSize)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def distance(source, xs, ys, target, xt, yt, patchSize):
|
|
|
|
def distance(source, xs, ys, target, xt, yt, patchSize):
|
|
|
|
ssd_max = 9 * 255 * 255
|
|
|
|
ssd_max = 9 * 255 * 255
|
|
|
|
distance, wsum = 0, 0
|
|
|
|
distance, wsum = 0, 0
|
|
|
|