|
|
|
@ -13,7 +13,7 @@ def doPatchMatch(img,x1,y1,x2,y2,patchSize=17,nbRadomPatch=10):
|
|
|
|
|
return patch
|
|
|
|
|
|
|
|
|
|
def distance(patchValue1,patchValue2):
|
|
|
|
|
mask = np.all(patchValue1 == [-1, -1, -1, -1], axis=-1)
|
|
|
|
|
mask = np.all(patchValue1 == [0, 0, 0], axis=-1)
|
|
|
|
|
return np.sum((patchValue1[~mask] - patchValue2[~mask]) ** 2)
|
|
|
|
|
|
|
|
|
|
def getBestNeigbourPatch(xy,ogValue,ogDist,step):
|
|
|
|
@ -112,7 +112,7 @@ def doPatchMatch(img,x1,y1,x2,y2,patchSize=17,nbRadomPatch=10):
|
|
|
|
|
for y in range(y1 + 1, y2):
|
|
|
|
|
perimeter.append((x1, y))
|
|
|
|
|
perimeter.append((x2, y))
|
|
|
|
|
img[y1:y2+1, x1:x2+1] = -1
|
|
|
|
|
img[y1:y2+1, x1:x2+1] = 0
|
|
|
|
|
return np.array(perimeter)
|
|
|
|
|
|
|
|
|
|
def removeAndAddFromPerimiter(perimiter, addr):
|
|
|
|
@ -129,7 +129,7 @@ def doPatchMatch(img,x1,y1,x2,y2,patchSize=17,nbRadomPatch=10):
|
|
|
|
|
if (dx!=-1 and dx!=p1-1 and dy != -1 and dy != p1-1):
|
|
|
|
|
continue
|
|
|
|
|
nx, ny = addr[0,0] + dx, addr[0,1] + dy
|
|
|
|
|
if 0 <= nx < width and 0 <= ny < height and img[ny, nx][0] == -1:
|
|
|
|
|
if 0 <= nx < width and 0 <= ny < height and img[ny, nx][0] == 0:
|
|
|
|
|
if len(perimiter) == 0:
|
|
|
|
|
perimiter.append([nx, ny])
|
|
|
|
|
continue
|
|
|
|
@ -138,9 +138,12 @@ def doPatchMatch(img,x1,y1,x2,y2,patchSize=17,nbRadomPatch=10):
|
|
|
|
|
return perimiter
|
|
|
|
|
|
|
|
|
|
def applyPatch(patch,addr):
|
|
|
|
|
value = patchToValue(addr)
|
|
|
|
|
mask = np.all(value == [0, 0, 0], axis=-1)
|
|
|
|
|
# regénérer addr en fonction du mask et des value
|
|
|
|
|
patch = patch[~mask]
|
|
|
|
|
for i in range(len(addr)):
|
|
|
|
|
if img[addr[i, 1], addr[i, 0]][0] == -1:
|
|
|
|
|
img[addr[i, 1], addr[i, 0]] = img[patch[i, 1],patch[i, 0]]
|
|
|
|
|
img[addr[i, 1], addr[i, 0]] = img[patch[i, 1],patch[i, 0]]
|
|
|
|
|
|
|
|
|
|
def getRandomFromPerimiter(perimiter):
|
|
|
|
|
return perimiter[np.random.randint(len(perimiter))]
|
|
|
|
@ -185,7 +188,7 @@ def doPatchMatch(img,x1,y1,x2,y2,patchSize=17,nbRadomPatch=10):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
img = plt.imread('asset/boat.png')
|
|
|
|
|
img = plt.imread('asset/mur.jpg')
|
|
|
|
|
|
|
|
|
|
if len(img.shape) == 2:
|
|
|
|
|
img = np.stack((img,)*3, axis=-1)
|
|
|
|
|