dst = cv2.inpaint(src, inpaintMask, inpaintRadius, flags)
dst: 복원이 완요된 이미지를 저장하기 위한 변수
src : 복원이 필요한 이미지
inpaintMask : 복원이 필요한 영역을 지정한 마스크
inpaintRadius : 복원을 진행할때 참고 하는 영역, 일반적으로는 적은 반경을 참고 할 수록 복원이미지에서 blur효과가 적어진다.
flags:INPAINT_NS
(Navier-Stokes based method) 혹은INPAINT_TELEA
(Fast marching based method)
수학적 설명이 필요한 경우에는 아래 논문을 참고
Navier-Stokes, Fluid Dynamics, and Image and Video Inpainting
수학적 설명이 필요한 경우에는 아래 논문을 참고
An Image Inpainting Technique Based on the Fast Marching Method
import cv2
import numpy as np
import matplotlib.pyplot as plt
# Read image in color mode.
filename = "images/Lincoln.jpg"
img = cv2.imread(filename, cv2.IMREAD_COLOR)
# If image is not read properly, return error.
if img is None:
print('Failed to load image file: {}'.format(filename))
# Read image in color mode.
filename = "images/Lincoln.jpg"
img = cv2.imread(filename, cv2.IMREAD_COLOR)
# If image is not read properly, return error.
if img is None:
print('Failed to load image file: {}'.format(filename))
# Create a copy of original image.
img_mask = img.copy()
# Create a black copy of original image, acts as a mask.
inpaintMask = np.zeros(img.shape[:2], np.uint8)
while True:
ch = cv2.waitKey()
if ch == 27:
cv2.destroyAllWindows()
break
if ch == ord('t'):
# Use Algorithm proposed by Alexendra Telea: Fast Marching Method (2004).
res_FMM = cv2.inpaint(src=img_mask, inpaintMask=inpaintMask, inpaintRadius=3, flags=cv2.INPAINT_TELEA)
cv2.imshow('Inpaint Output using FMM', res_FMM)
if ch == ord('n'):
res_NS = cv2.inpaint(src = img_mask, inpaintMask = inpaintMask, inpaintRadius=3, flags=cv2.INPAINT_NS)
cv2.imshow('Inpaint Output using NS Technique', res_NS)
if ch == ord('r'):
img_mask[:] = img
inpaintMask[:] = 0
sketch.show()
복원시도 전
복원시도 후