# 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 4.

1

Wikipedia. Inpainting https://en.wikipedia.org/wiki/Inpainting

2

Wikipedia. Biharmonic equation https://en.wikipedia.org/wiki/Biharmonic_equation

3

S.B.Damelin and N.S.Hoang. “On Surface Completion and Image Inpainting by Biharmonic Functions: Numerical Aspects”, International Journal of Mathematics and Mathematical Sciences, Vol. 2018, Article ID 3950312 DOI:10.1155/2018/3950312

4

C. K. Chui and H. N. Mhaskar, MRA Contextual-Recovery Extension of Smooth Functions on Manifolds, Appl. and Comp. Harmonic Anal., 28 (2010), 104-113, DOI:10.1016/j.acha.2009.04.004 ```import numpy as np
import matplotlib.pyplot as plt

from skimage import data
from skimage.morphology import disk, binary_dilation
from skimage.restoration import inpaint

image_orig = data.astronaut()

# Create mask with six block defect regions

# add a few long, narrow defects

# add randomly positioned small point-like defects
rstate = np.random.default_rng(0)
for radius in [0, 2, 4]:
# larger defects are less common
thresh = 3 + 0.25 * radius  # make larger defects less commmon

# Apply defect mask to the image over the same region in each color channel
image_defect = image_orig * ~mask[..., np.newaxis]

fig, axes = plt.subplots(ncols=2, nrows=2)
ax = axes.ravel()

ax.set_title('Original image')
ax.imshow(image_orig)

ax.set_title('Defected image')
ax.imshow(image_defect)

ax.set_title('Inpainted image')
ax.imshow(image_result)

for a in ax:
a.axis('off')

fig.tight_layout()
plt.show()
```

Total running time of the script: ( 0 minutes 0.588 seconds)

Gallery generated by Sphinx-Gallery