diff --git a/asset/mur.jpg b/asset/mur.jpg deleted file mode 100644 index 69fbc1f..0000000 Binary files a/asset/mur.jpg and /dev/null differ diff --git a/demo/demo1.png b/demo/demo1.png new file mode 100644 index 0000000..c8056c9 Binary files /dev/null and b/demo/demo1.png differ diff --git a/demo/demo2.png b/demo/demo2.png new file mode 100644 index 0000000..f067228 Binary files /dev/null and b/demo/demo2.png differ diff --git a/demo/demo2_mask.png b/demo/demo2_mask.png new file mode 100644 index 0000000..ee5a5b5 Binary files /dev/null and b/demo/demo2_mask.png differ diff --git a/demo/demo3.png b/demo/demo3.png new file mode 100644 index 0000000..80f7e49 Binary files /dev/null and b/demo/demo3.png differ diff --git a/demo/demo3_mask.png b/demo/demo3_mask.png new file mode 100644 index 0000000..dffabec Binary files /dev/null and b/demo/demo3_mask.png differ diff --git a/demo/demo4.png b/demo/demo4.png new file mode 100644 index 0000000..91e4600 Binary files /dev/null and b/demo/demo4.png differ diff --git a/demo/demo4_mask.png b/demo/demo4_mask.png new file mode 100644 index 0000000..0da986a Binary files /dev/null and b/demo/demo4_mask.png differ diff --git a/function.py b/function.py index 4eb70b0..7780232 100644 --- a/function.py +++ b/function.py @@ -1,9 +1,11 @@ +from maskedImage import MaskedImage import matplotlib.pyplot as plt +from nnf import Nnf import numpy as np +import threading import cv2 -from maskedImage import MaskedImage -from nnf import Nnf +import concurrent.futures def read(file): img = plt.imread(file) @@ -41,7 +43,7 @@ def doTheInpainting(img,mask,radius): upscaled = False vote = np.zeros((newTarget.width, newTarget.height, 4)) - ExpectationStep(targetToSource,False,vote,newSource,upscaled) + ExpectationStep(targetToSource,vote,newSource,upscaled) MaximizationStep(newTarget, vote) result = cv2.resize(newTarget.image, (initial.width, initial.height), interpolation=cv2.INTER_AREA) plt.imshow(result) @@ -79,38 +81,39 @@ def doTheInpainting(img,mask,radius): plt.pause(0.01) return target.image -def ExpectationStep(nnf,sourceToTarget, vote, source, upscale): - for y in range(nnf.input.height): - for x in range(nnf.input.width): - xp, yp, dp = nnf.field[y,x] - w = MaskedImage.similarity[dp] - for dy in range(-nnf.patchSize,nnf.patchSize): - for dx in range(-nnf.patchSize,nnf.patchSize): - if sourceToTarget: - xs = x+dx - ys = y+dy - xt = xp+dx - yt = yp+dy - else: +def ExpectationStep(nnf, vote, source, upscale): + def ExpectationStepForNb(nb): + hei = nnf.input.height//7 + for y in range(nb*hei,(nb+1)*hei if nb != 7 else nnf.input.height): + for x in range(nnf.input.width): + xp, yp, dp = nnf.field[y,x] + w = MaskedImage.similarity[dp] + for dy in range(-nnf.patchSize,nnf.patchSize): + for dx in range(-nnf.patchSize,nnf.patchSize): xs = xp+dx ys = yp+dy xt = x+dx yt = y+dy - if not 0<=xs