In [2]:
import algorithm as al
import numpy as np
import cv2 as cv
import Queue
from patchdb import *
from psi import *
from copyutils import *
from debug import *
import inspect
In [3]:
def imshow(img):
cv.imshow('image', img)
cv.waitKey(0)
cv.destroyAllWindows()
In [92]:
_p.readImage('../../test_images/Kanizsa-triangle-tiny.png', 'source')
_p.readImage('../../test_images/Kanizsa-triangle-mask-tiny.png', 'alpha')
Out[92]:
In [93]:
_p._images['filled'] = np.uint8(_p._images['alpha'] > 0)*255
_p._images['inpainted'] = _p._images['source'].copy()
In [94]:
_p._images['source'].shape
Out[94]:
In [95]:
for i in range(0,3):
_p._images['inpainted'][:,:,i] *= (_p._images['filled']>0)
#
# Step 1a,b: Identify the fill front deltaOmega and compute
# initial patch priorities
In [96]:
_p.computeBoundaries()
_p.confidenceInitialize()
In [97]:
_p._w = 5
In [98]:
_p._patchDB = PatchDB(_p._images['inpainted'], _p._w, filled=_p._images['filled'])
In [99]:
_p.iterationsInit()
done = False
In [100]:
boundary = _p._boundaryIterator.next()
_p.fillFrontInitialize(boundary, imviewer=None)
In [101]:
boundaryPixels = boundary
# initialize the pixels on the fill front
_p._images['fillFront'] = \
np.zeros_like(_p._images['filled'], dtype=np.uint8)
_p._images['fillFront'] = \
cv.drawContours(_p._images['fillFront'],boundaryPixels,-1,255)
# initialize the priority queue with all points on the fill front
_p._deltaOmega = Queue.PriorityQueue()
In [135]:
# col, row = boundaryPixels[10][0]
col, row = boundary[150:200][0][0]
p = PSI((row, col), _p._w,
image=_p._images['inpainted'],
filled=_p._images['filled'],
confidence=_p._images['confidence'],
fillFront=_p._images['fillFront'])
inpaintedImage=_p._images['inpainted']
filledImage=_p._images['filled']
confidence=_p._images['confidence']
fillFront=_p._images['fillFront']
In [151]:
front, _ = copyutils.getWindow(fillFront, p._coords, p._w)
# filled, _ = copyutils.getWindow(filledImage, psiHatP._coords, psiHatP._w)
# Sobel filter
kw = 1
size = 2 * kw + 1
Gx = cv.Sobel(src=front, ddepth=cv.CV_32F, dx=1, dy=0, ksize=size)[p._w][p._w]
Gy = cv.Sobel(src=front, ddepth=cv.CV_32F, dx=0, dy=1, ksize=size)[p._w][p._w]
d = np.sqrt(Gy**2 + Gx**2)
if d != 0:
Gx /= d
Gy /= d
Ny = Gy
Nx = -Gx
In [152]:
front
Out[152]:
In [155]:
Gx
Out[155]:
In [106]:
erode_kernel = np.ones((3,3),np.uint8);kernel
Out[106]:
In [107]:
filled_eroded = cv.erode(inpainted, erode_kernel, borderType=cv.BORDER_REPLICATE,iterations=1);filled_eroded
Out[107]:
In [108]:
dx = cv.Sobel(src=inpainted, ddepth=cv.CV_32F, dx=1, dy=0, ksize=3, borderType=cv.BORDER_REPLICATE);dx
Out[108]:
In [109]:
dx *= filled_eroded > 0
In [110]:
dx
Out[110]:
In [111]:
Dx * (filled>0)
Out[111]:
In [112]:
d
Out[112]:
In [113]:
Dx[dmax][0]
Out[113]:
In [114]:
Dy[dmax][0]
Out[114]:
In [ ]: