src/utils.py
def extend_mask_nonlocal(mask,kernel=np.ones((3,3))):
	"""
	Extend inpainting mask to contain pixels in the support of the nonlocal kernel
	"""
	assert (mask.dtype is np.dtype(np.bool)), "input mask must be of bool type"

	ext_mask = mask.copy()
	inp_ind  = masked_indices(mask)
	im_h, im_w = mask.shape

	ker_y, ker_x = kernel.shape
	assert(ker_x%2>0), "kernel must have odd dimensions"
	assert(ker_y%2>0), "kernel must have odd dimensions"

	# indices of the nonzero kernel elements
	ker_ind_y, ker_ind_x = np.nonzero(kernel)
	ker_ind_x -= ker_x//2
	ker_ind_y -= ker_y//2

	for ind_x, ind_y in zip(inp_ind%im_w, inp_ind//im_w):
		for i, j in zip(ker_ind_x, ker_ind_y):
			ext_mask[min(max(0,ind_y+j),im_h-1),min(max(0,ind_x+i),im_w-1)] = True

	return ext_mask

	Extend inpainting mask to contain pixels in the support of the nonlocal kernel
	
Extend inpainting mask to contain pixels in the support of the nonlocal kernel
Extend inpainting mask to contain pixels in the support of the nonlocal kernel
def extend_mask_nonlocal(mask,kernel=np.ones((3,3))):
	assert (mask.dtype is np.dtype(np.bool)), "input mask must be of bool type"
	ext_mask = mask.copy()
	inp_ind  = masked_indices(mask)
	im_h, im_w = mask.shape
	ker_y, ker_x = kernel.shape
	assert(ker_x%2>0), "kernel must have odd dimensions"
	assert(ker_y%2>0), "kernel must have odd dimensions"
	ker_ind_y, ker_ind_x = np.nonzero(kernel)
	ker_ind_x -= ker_x//2
	ker_ind_y -= ker_y//2
	for ind_x, ind_y in zip(inp_ind%im_w, inp_ind//im_w):
		for i, j in zip(ker_ind_x, ker_ind_y):
			ext_mask[min(max(0,ind_y+j),im_h-1),min(max(0,ind_x+i),im_w-1)] = True
	return ext_mask
def extend_mask_nonlocal ( mask , kernel = np . ones ( ( 3 , 3 ) ) ) : assert ( mask . dtype is np . dtype ( np . bool ) ) , "input mask must be of bool type" ext_mask = mask . copy ( ) inp_ind = masked_indices ( mask ) im_h , im_w = mask . shape ker_y , ker_x = kernel . shape assert ( ker_x % 2 > 0 ) , "kernel must have odd dimensions" assert ( ker_y % 2 > 0 ) , "kernel must have odd dimensions" ker_ind_y , ker_ind_x = np . nonzero ( kernel ) ker_ind_x -= ker_x // 2 ker_ind_y -= ker_y // 2 for ind_x , ind_y in zip ( inp_ind % im_w , inp_ind // im_w ) : for i , j in zip ( ker_ind_x , ker_ind_y ) : ext_mask [ min ( max ( 0 , ind_y + j ) , im_h - 1 ) , min ( max ( 0 , ind_x + i ) , im_w - 1 ) ] = True return ext_mask
Extend inpainting mask to contain pixels in the support of the nonlocal kernel
Extend inpainting mask to contain pixels in the support of the nonlocal kernel
"""
	Extend inpainting mask to contain pixels in the support of the nonlocal kernel
	""" # indices of the nonzero kernel elements
mask
kernel