Merge pull request #1804 from soupault/inpainting

ENH: Inpainting with biharmonic equation
This commit is contained in:
Juan Nunez-Iglesias
2016-01-18 10:56:24 +11:00
3 changed files with 263 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
"""
===========
Inpainting
===========
Inpainting [1]_ is the process of reconstructing lost or deteriorated
parts of images and videos.
The reconstruction is supposed to be performed in fully automatic way by
exploiting the information presented in non-damaged regions.
In this example, we show how the masked pixels get inpainted by
inpainting algorithm based on 'biharmonic equation'-assumption [2]_ [3]_.
.. [1] Wikipedia. Inpainting
https://en.wikipedia.org/wiki/Inpainting
.. [2] Wikipedia. Biharmonic equation
https://en.wikipedia.org/wiki/Biharmonic_equation
.. [3] N.S.Hoang, S.B.Damelin, "On surface completion and image
inpainting by biharmonic functions: numerical aspects",
http://www.ima.umn.edu/~damelin/biharmonic
"""
import numpy as np
import matplotlib.pyplot as plt
from skimage import data, color
from skimage.restoration import inpaint
image_orig = data.astronaut()
# Create mask with three defect regions: left, middle, right respectively
mask = np.zeros(image_orig.shape[:-1])
mask[20:60, 0:20] = 1
mask[200:300, 150:170] = 1
mask[50:100, 400:430] = 1
# Defect image over the same region in each color channel
image_defect = image_orig.copy()
for layer in range(image_defect.shape[-1]):
image_defect[np.where(mask)] = 0
image_result = inpaint.inpaint_biharmonic(image_defect, mask, multichannel=True)
fig, axes = plt.subplots(ncols=3, nrows=1)
axes[0].set_title('Defected image')
axes[0].imshow(image_orig)
axes[0].set_xticks([]), axes[0].set_yticks([])
axes[1].set_title('Defect mask')
axes[1].imshow(mask, cmap=plt.cm.gray)
axes[1].set_xticks([]), axes[1].set_yticks([])
axes[2].set_title('Inpainted image')
axes[2].imshow(image_result)
axes[2].set_xticks([]), axes[2].set_yticks([])
plt.show()