备注
单击 here 下载完整的示例代码或通过活页夹在浏览器中运行此示例
修复¶
修复 1 是重建图像和视频中丢失或损坏的部分的过程。
重建应该通过利用非受损区域提供的信息,以全自动的方式进行。
在这个例子中,我们展示了如何通过基于‘双调和方程’假设的修复算法来修复被遮蔽的像素 2 3 4.
- 1
维基百科。修复https://en.wikipedia.org/wiki/Inpainting
- 2
维基百科。双调和方程https://en.wikipedia.org/wiki/Biharmonic_equation
- 3
S.S.Hoang,S.B.Damelin,《关于双调和函数的曲面补全和图像修复:数值方面》, arXiv:1707.06567
- 4
徐春凯,H.N.Mhaskar,流形上光滑函数的MRA上下文-恢复扩张,应用.和Comp.和声分析,28(2010),104-113, DOI:10.1016/j.acha.2009.04.004

输出:
/scikit-image/doc/examples/filters/plot_inpaint.py:46: FutureWarning:
`multichannel` is a deprecated argument name for `inpaint_biharmonic`. It will be removed in version 1.0. Please use `channel_axis` instead.
import numpy as np
import matplotlib.pyplot as plt
from skimage import data
from skimage.restoration import inpaint
image_orig = data.astronaut()[0:200, 0:200]
# Create mask with three defect regions: left, middle, right respectively
mask = np.zeros(image_orig.shape[:-1])
mask[20:60, 0:20] = 1
mask[160:180, 70:155] = 1
mask[30:60, 170:195] = 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=2, nrows=2)
ax = axes.ravel()
ax[0].set_title('Original image')
ax[0].imshow(image_orig)
ax[1].set_title('Mask')
ax[1].imshow(mask, cmap=plt.cm.gray)
ax[2].set_title('Defected image')
ax[2].imshow(image_defect)
ax[3].set_title('Inpainted image')
ax[3].imshow(image_result)
for a in ax:
a.axis('off')
fig.tight_layout()
plt.show()
脚本的总运行时间: (0分0.163秒)