def inpaint(self, rescale_factor=1.0):
""" Fills in the zero pixels in the image.
Parameters
----------
rescale_factor : float
amount to rescale the image for inpainting, smaller numbers increase speed
Returns
-------
:obj:`DepthImage`
depth image with zero pixels filled in
"""
# form inpaint kernel
inpaint_kernel = np.array([[1, 1, 1], [1, 0, 1], [1, 1, 1]])
# resize the image
resized_data = self.resize(rescale_factor, interp='nearest').data
# inpaint the smaller image
cur_data = resized_data.copy()
zeros = (cur_data == 0)
while np.any(zeros):
neighbors = ssg.convolve2d((cur_data != 0), inpaint_kernel,
mode='same', boundary='symm')
avg_depth = ssg.convolve2d(cur_data, inpaint_kernel,
mode='same', boundary='symm')
avg_depth[neighbors > 0] = avg_depth[neighbors > 0] / \
neighbors[neighbors > 0]
avg_depth[neighbors == 0] = 0
avg_depth[resized_data > 0] = resized_data[resized_data > 0]
cur_data = avg_depth
zeros = (cur_data == 0)
# fill in zero pixels with inpainted and resized image
inpainted_im = DepthImage(cur_data, frame=self.frame)
filled_data = inpainted_im.resize(
1.0 / rescale_factor, interp='bilinear').data
new_data = np.copy(self.data)
new_data[self.data == 0] = filled_data[self.data == 0]
return DepthImage(new_data, frame=self.frame)
评论列表
文章目录