fin des optimization

master
Ludovic CASTIGLIA 4 months ago
parent 7a5e1081bc
commit 2498b92908

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 532 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 530 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

@ -1,9 +1,11 @@
from maskedImage import MaskedImage
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from nnf import Nnf
import numpy as np import numpy as np
import threading
import cv2 import cv2
from maskedImage import MaskedImage import concurrent.futures
from nnf import Nnf
def read(file): def read(file):
img = plt.imread(file) img = plt.imread(file)
@ -41,7 +43,7 @@ def doTheInpainting(img,mask,radius):
upscaled = False upscaled = False
vote = np.zeros((newTarget.width, newTarget.height, 4)) vote = np.zeros((newTarget.width, newTarget.height, 4))
ExpectationStep(targetToSource,False,vote,newSource,upscaled) ExpectationStep(targetToSource,vote,newSource,upscaled)
MaximizationStep(newTarget, vote) MaximizationStep(newTarget, vote)
result = cv2.resize(newTarget.image, (initial.width, initial.height), interpolation=cv2.INTER_AREA) result = cv2.resize(newTarget.image, (initial.width, initial.height), interpolation=cv2.INTER_AREA)
plt.imshow(result) plt.imshow(result)
@ -79,38 +81,39 @@ def doTheInpainting(img,mask,radius):
plt.pause(0.01) plt.pause(0.01)
return target.image return target.image
def ExpectationStep(nnf,sourceToTarget, vote, source, upscale): def ExpectationStep(nnf, vote, source, upscale):
for y in range(nnf.input.height): def ExpectationStepForNb(nb):
for x in range(nnf.input.width): hei = nnf.input.height//7
xp, yp, dp = nnf.field[y,x] for y in range(nb*hei,(nb+1)*hei if nb != 7 else nnf.input.height):
w = MaskedImage.similarity[dp] for x in range(nnf.input.width):
for dy in range(-nnf.patchSize,nnf.patchSize): xp, yp, dp = nnf.field[y,x]
for dx in range(-nnf.patchSize,nnf.patchSize): w = MaskedImage.similarity[dp]
if sourceToTarget: for dy in range(-nnf.patchSize,nnf.patchSize):
xs = x+dx for dx in range(-nnf.patchSize,nnf.patchSize):
ys = y+dy
xt = xp+dx
yt = yp+dy
else:
xs = xp+dx xs = xp+dx
ys = yp+dy ys = yp+dy
xt = x+dx xt = x+dx
yt = y+dy yt = y+dy
if not 0<=xs<nnf.input.width: if not 0<=xs<nnf.input.width:
continue continue
if not 0<=ys<nnf.input.height: if not 0<=ys<nnf.input.height:
continue continue
if not 0<=xt<nnf.input.width: if not 0<=xt<nnf.input.width:
continue continue
if not 0<=yt<nnf.input.height: if not 0<=yt<nnf.input.height:
continue continue
if upscale: if upscale:
weightedCopy(source,2*xs,2*ys,vote,2*xt,2*yt,w) weightedCopy(source,2*xs,2*ys,vote,2*xt,2*yt,w)
weightedCopy(source,2*xs+1,2*ys,vote,2*xt+1,2*yt,w) weightedCopy(source,2*xs+1,2*ys,vote,2*xt+1,2*yt,w)
weightedCopy(source,2*xs,2*ys+1,vote,2*xt,2*yt+1,w) weightedCopy(source,2*xs,2*ys+1,vote,2*xt,2*yt+1,w)
weightedCopy(source,2*xs+1,2*ys+1,vote,2*xt+1,2*yt+1,w) weightedCopy(source,2*xs+1,2*ys+1,vote,2*xt+1,2*yt+1,w)
else: else:
weightedCopy(source,xs,ys,vote,xt,yt,w) weightedCopy(source,xs,ys,vote,xt,yt,w)
pool = concurrent.futures.ThreadPoolExecutor(max_workers=8)
for i in range(8):
pool.submit(ExpectationStepForNb,i)
pool.shutdown(wait=True)
def weightedCopy(src,xs,ys,vote,xd,yd,w): def weightedCopy(src,xs,ys,vote,xd,yd,w):
if src.mask[ys,xs]: if src.mask[ys,xs]:

Loading…
Cancel
Save